Suppose I want to have a link or a button that when user click it, the browser will close without any confirmation dialog box.
It will need to work on Internet Explorer 6, 7, 8 and Firefox.
Suppose I want to have a link or a button that when user click it, the browser will close without any confirmation dialog box.
It will need to work on Internet Explorer 6, 7, 8 and Firefox.
Duplicate: how-can-i-close-a-browser-window-without-receiving-the-do-you-want-to-close-this
Another great SO answer on this topic:
Duplicate: closing-browser-after-failing-to-login
And just another duplicate:
That would be a major security breach. You will never be able to do that.
You can, however, close child windows the parent has opened. Say you opened a popup with a parent window, that same parent window can have a button to close the child. Never the browser.
I think part of the issue here is that you are unclear about your goal in the question. From your comment on Frankie's answer, it seems that you don't really need to close the window at all, you simply need to secure the content that was available in the window.
Here is what I recommend:
Frankly, it's usually better to keep a user on your site until the moment that -they- want to close the tab or otherwise browse away anyway. Just redirect them to a landing page that doesn't need to be secure instead of trying to force closing of the tab.
I have done some research and found out that it is not possible to close window/tab in Firefox if that window/tab isn't open through javascript or if the tab has history pages > 1 (i.e. Back button clickable because you browse through webpages).
Way to do in Firefox : Delete the history first. Then you can close window without confirmation box. I haven't tried this solution. I happen to read through multiple reliable pages that describe how to do this.
Solution for Internet Explorer 6, 7, 8.
With a little help from browser detect function : http://www.quirksmode.org/js/detect.html , here is how to close window without comfirmation box for multiple IE versions.
if ((userBrowser.browser == "Explorer" && (userBrowser.version == "8" || userBrowser.version == "7"))) {
window.open('', '_self', '');
window.close();
} else if ((userBrowser.browser == "Explorer" && userBrowser.version == "6")) {
window.opener = null;
window.close();
} else {
window.opener = '';
window.close(); // attempt to close window first, show user warning message if fails
alert("To avoid data corruption/loss. Please close this window immedietly.");
}
I know that some of you might think that using browser detect isn't a good idea. Also, many believe that forcing users to close window is a bad thing. I agree to those idea. But, I just need it because of software requirement we are told to do.
Hope this helps.