Suppose, I want to have a link or a button that when user click it, will close the browser without any confirmation dialog box.
It needs to work in Internet Explorer 6, 7, 8 and Firefox.
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.