用于关闭浏览器的 JavaScript/jquery FireFox/chrome/IE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7529641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript/ jquery for Closing Browser FireFox / chrome / IE
提问by BJ Patel
AS I need JavaScript / jquery Code for Closing Browser's ( FireFox / Chrome and IE..)
因为我需要 JavaScript/jquery 代码来关闭浏览器(FireFox/Chrome 和 IE..)
As I have try with window.close()
正如我尝试使用 window.close()
But it only work for IE.
但它只适用于 IE。
Is any other way..?
还有其他方法吗..?
回答by Marco acuna
This worked for IE and Chrome. (window.close() worked for IE, then win.close for chrome)
这适用于 IE 和 Chrome。(window.close() 适用于 IE,然后 win.close 适用于 chrome)
<script type="text/javascript">
function CloseThis() {
var win = window.open('', '_self');
window.close();
win.close(); return false;
}
</script>
回答by BJ Patel
Can check Browser and write respective script for IE / FireFox
可以检查浏览器并为 IE / FireFox 编写相应的脚本
IE---->
浏览器---->
window.close()
FireFox --->
火狐--->
var answer = confirm("Do you want to close this window ?");
if (answer){
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
window.close();
}
else{
stop;
}
回答by gion_13
I don't think that is possible as javascript can only interact with the pages rendered by the browser, not the actual browser.
我认为这是不可能的,因为 javascript 只能与浏览器呈现的页面交互,而不是实际的浏览器。
回答by mmcnickle
Windows can only be closed by scripts (window.close()) that were opened by scripts in the first place. So generally, this isn't possible (https://developer.mozilla.org/en/DOM/window.close)
Windows 只能由最初由脚本打开的脚本 (window.close()) 关闭。所以一般来说,这是不可能的(https://developer.mozilla.org/en/DOM/window.close)
回答by Andreas Eriksson
Try this snippet
试试这个片段
window.close()