JavaScript关闭IE6,IE7,IE8和Firefox没有确认框? [英] Javascript to close IE6, IE7, IE8 and Firefox without confirmation box?

查看:182
本文介绍了JavaScript关闭IE6,IE7,IE8和Firefox没有确认框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想要一个链接或一个按钮,当用户点击它时,浏览器将在没有任何确认对话框的情况下关闭。



它需要工作Internet Explorer 6,7,8和Firefox。

解决方案

我已经做了一些调查,发现无法关闭如果该窗口/选项卡没有通过JavaScript打开,或者该选项卡的历史记录页面大于1(即后退按钮可点击,因为您浏览网页),则在Firefox中的窗口/选项卡。



<在Firefox中的方法:先删除历史记录。然后,您可以关闭窗口而无需确认框。我还没有尝试过这个解决方案。我碰巧通过多个可靠的网页来描述如何做到这一点。



Internet Explorer 6,7,8的解决方案



借助浏览器检测功能: http: //www.quirksmode.org/js/detect.html ,下面是如何关闭多个IE版本没有确认框的窗口。

 ((userBrowser.browser ==Explorer&&(userBrowser.version ==8|| userBrowser.version ==7))){
window。打开('','_self','');
window.close();
} else if((userBrowser.browser ==Explorer&& userBrowser.version ==6)){
window.opener = null;
window.close();
} else {
window.opener ='';
window.close(); //尝试先关闭窗口,如果失败则显示用户警告消息
alert(为了避免数据损坏/丢失,请立即关闭此窗口。





$ b我知道你们中的一些人可能会认为使用浏览器检测不是好主意。此外,许多人认为强迫用户关闭窗户是一件坏事。我同意这些想法。但是,我只是需要它,因为我们被告知需要软件的要求。

希望这有助于。


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.

解决方案

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.

这篇关于JavaScript关闭IE6,IE7,IE8和Firefox没有确认框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆