JavaScript 关闭页面(IE, firefox, Chrome)兼容问题
设计页面时加上了Exit按钮,希望点击之后浏览器页面可以自动关闭。用JavaScript写了下面的脚本:
<script language="javascript" type="text/javascript">
function winClose()
{
window.close();
}
</script>
但是发现在Firefox,跟Chrome浏览器中,这段脚本不起作用,上网查了之后发现这段介绍:
众所周知,在javascript中window.close()是用来关闭窗口的,而且ie和firefox都是支持的。为了实现用户对浏览器的绝对控制,ie中用close关闭非open打开的窗口时会弹出一个对话框询问用户。有时候我们不希望再这样哆嗦,但是怎么去掉这个框呢,请看下面的代码。 function winClose(){ window.top.opener = null; window.close(); } 在window.close之前加上window.top.opener = null就可以了。 不过,把上面的代码用来试一下的话,我们会发现,在FireFox中好像没起作用。会不会是firefox不支持close,其实不然。之所以window.close在firefox不能使用,是因为firefox默认不能关闭用户打开的网页,我们可以这样设置firefox: 打开firefox,在地址栏输入about:config 找到dom.allow_scripts_to_close_windows这项并改为true。 再把上面的代码用来试一下吧! |
Ref:http://hi.baidu.com/suen_%CB%EF/blog/item/bedca57f8932480d28388a49.html
2020年12月14日 00:17
Having email is a essential thing when you use internet, but to use email more effectively is not easy, hotmail email login has the tutorial and tips you need.