I have created an ASP.Net application page to handle opening FileSite links. There is a custom protocol which is handling the links correctly, i.e it opens the files, however it leaves me with an empty browser page as the file is launched.
I have 3 scenarios I am working with
- Links directly to the handling page will launch the file and close the browser
- Links from another page on the Intranet will launch handling page, open the file and return to the originating page
- Links from a dialog on the Intranet open the handling page, launch the file and then close the handling page
The code I have is the following (Codebehind is setting the FileUrl and choosing which function to call of the two)
<script type="text/javascript" language="javascript">
// Files opened directly from link
function OpenFileSiteLink() {
window.location.href = '<%= FileUrl %>';
}
// Files opened from within Intranet
function OpenFileSiteLinkReferrer(referrer, dialogOpened) {
window.open('<%= FileUrl %>');
if (dialogOpened) {
window.open('close.html', '_self');
} else {
window.location.href = referrer;
}
}
</script>
The code in the close.html file has only the following
<script type="text/javascript"> window.close();</script>
This was taken from How can I close a browser window without receiving the "Do you want to close this window" prompt?
Any suggestions how I can open the protocol to launch the application without the additional dialog would be appreciated
I have created an ASP.Net application page to handle opening FileSite links. There is a custom protocol which is handling the links correctly, i.e it opens the files, however it leaves me with an empty browser page as the file is launched.
I have 3 scenarios I am working with
- Links directly to the handling page will launch the file and close the browser
- Links from another page on the Intranet will launch handling page, open the file and return to the originating page
- Links from a dialog on the Intranet open the handling page, launch the file and then close the handling page
The code I have is the following (Codebehind is setting the FileUrl and choosing which function to call of the two)
<script type="text/javascript" language="javascript">
// Files opened directly from link
function OpenFileSiteLink() {
window.location.href = '<%= FileUrl %>';
}
// Files opened from within Intranet
function OpenFileSiteLinkReferrer(referrer, dialogOpened) {
window.open('<%= FileUrl %>');
if (dialogOpened) {
window.open('close.html', '_self');
} else {
window.location.href = referrer;
}
}
</script>
The code in the close.html file has only the following
<script type="text/javascript"> window.close();</script>
This was taken from How can I close a browser window without receiving the "Do you want to close this window" prompt?
Any suggestions how I can open the protocol to launch the application without the additional dialog would be appreciated
Share Improve this question edited May 23, 2017 at 12:23 CommunityBot 11 silver badge asked Jul 9, 2013 at 10:02 Phill DuffyPhill Duffy 2,8663 gold badges33 silver badges48 bronze badges3 Answers
Reset to default 5 +25The least hacky and most reliable method to do this is the most annoying to implement. Unfortunately, IE 9/10 and Firefox have plugged up the regular methods of acplishing this, so you may have no other choice.
The strategy is to e at the popup from the parent window, rather than opening it directly. You will need to create a function to load the appropriate url in a popup, and then apply it to the onclick of every link on your linking to the url of the handler. Then, include this script on every page on your site. I am also assuming that each file url is unique, but has a mon base url of some kind. If this is not the case, you will also need to set an identifying class or attribute. The function to do the replacement would be something along the lines of:
var replaceHandlerLinks = function () {
var fileLinks = document.querySelectorAll("[href*='/beginning/to/file/path']");
for (var i = 0; i < fileLinks.length; i++) {
fileLinks[i].onclick = function () {
var fileOpener = window.open(fileLinks[i].href);
//depending on how long your file takes to load, you may need to wait here
fileOpener.close();
}
}
}
The obvious downside of this being that any link to these files would need to originate from pages you control. Additionally, note that I am using document.querySelectorAll to target the links href element. This means that buttons etc will not work with this particular function. Using a more browser patible/robust query with JQuery or setting a class on all required buttons,links,etc would make this a more plete approach.
Another similar approach, if you need to link from pages you do not control, would be to always link to the same page from everywhere with a param, eg "/openfile.aspx?file=actualFilePath", then from that page open a popup to load the file, watch the new window and close it when the file is done. Then, attempt to redirect the current window based on scenario: 1) go to homepage/landing/etc 2) go to referrer 3) go to intranet landing/ referrer if possible. This isn't as elegant as just closing a popup from within itself, but it addresses the ugly blank window.
Neither approach is perfect, but outside of restricting users to ie8- and chrome, you may not have any other choice.
What about if you try to navigate into a <iframe>
instead of a new window?
Try to add a new <iframe>
to the DOM, navigate to your custom url, then remove the <iframe>
from the DOM. Do not bother to load the close.html page.
(disclaimer: to be honest, it's just an idea, I did no tried)
The iframe solution works for me :
var divgfa = document.getElementById('gfa');
var iframe = document.createElement("iframe");
iframe.src = "ticket://<?= $print ?>";
iframe.name = "frame"
divgfa.appendChild(iframe);