js关闭页面

转载博客:http://blog.sina.com.cn/s/blog_670eabd10100u6uw.html
以及:http://shensuqiao.iteye.com/blog/2112387?utm_source=tuicool&utm_medium=referral

JS中关闭窗口的方法window.close()在IE上能够正常动作,而在FireFox和Chrome上无法动作。
(当时,在Chrome35.0上的时候还是可以的,Chrome36.0上就无法动作了)

FireFox上的解决方法如下(已验证)
在Firefox地址栏里输入 about:config
将配置列表中的dom.allow_scripts_to_close_windows 设为true

Chrome上的解决方法有两种(这两种方法应该在FireFox上也是可行的,但未验证)
参考网页
http://stackoverflow.com/questions/2032640/problem-with-window-close-and-chrome

方法一:
window.open(…)
window.open(”, ‘_self’, ”);
window.close();

方法二:
window.open(…);
setTimeout(function(){
window.open(”, ‘_self’, ”);
window.close();
}, 100);

用多种方式打开一个页面,然后用 window.close() 关闭它,在各浏览器下表现有所不同。如在地址栏中直接输入URL 时,Firefox Chrome Safari 下调用 window.close() 关闭页面无效。再如 Ctrl + 点击链接打开的窗口,Firefox 下无法通过调用 window.close() 来关闭。

猜你喜欢

转载自blog.csdn.net/tongweiganglp/article/details/50436644
今日推荐