window.close()兼容

火狐浏览器除非设置脚本关闭窗口启用,不然无法关闭;

开启方法:

在Firefox地址栏里输入 about:config
在配置列表中找到 dom.allow_scripts_to_close_windows
点右键的选切换把上面的false修改为true即可。

但我们肯定不能告诉用户修改浏览器设置,所以无法关闭窗口,只能使用折中的方法,跳转到空页面;

function closeWindow() {
    var browserName = navigator.appName;
    if(browserName == 'Netscape') {
        var opened = window.open('about:blank','_self');
        opened.opener = null;
        opened.close();
    } else {
        window.opener = null;
        window.open('','_self');
        window.close();
    }
}

猜你喜欢

转载自kent-mu.iteye.com/blog/2262515
今日推荐