在Javascript中关闭窗口 [英] Close Window in Javascript
问题描述
我需要一种方法来使用Javascript关闭浏览器(而不是弹出窗口)。可能吗?
I need a way to close the browser (not a pop up) using Javascript. Is it possible?
推荐答案
如果某个JavaScript代码没有打开您自己域名的窗口,那么就不能使用JavaScript以交叉浏览器兼容的方式关闭它。只有在MSIE中你可以使用 window.close()
,但这会产生一个警告,但是通过调用 window.open('',可以解决这个问题。 '_self','');
事先。尽管如此,这在Firefox和其他不错的浏览器中都无效。并有充分的理由。您不应该强行关闭最终用户打开的窗口。这是糟糕的用户体验。
If the window isn't opened by some JavaScript code from your own domain, then you can't close it in a crossbrowsercompatible way using JavaScript. Only in MSIE you can use window.close()
, but this will generate a warning which is however workaroundable by calling window.open('', '_self', '');
beforehand. Still, this won't work in Firefox and other decent browsers. And with a good reason. You shouldn't forcibly close windows which the enduser opened itself. This is Bad User Experience.
这篇关于在Javascript中关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!