Javascript window.close 和 chrome 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2032640/
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
Issue with window.close and chrome
提问by mrpatg
Im trying to close a child window with javascript and in firefox everything works fine but in chrome the window doesnt close
我试图用 javascript 关闭子窗口,在 Firefox 中一切正常,但在 chrome 中窗口没有关闭
here is what im using
这是我正在使用的
$(document).ready(function() {
if (window.opener && !window.opener.closed)
window.opener.location = "http://www.website.com"
window.close();
});
I tried a suggestion on google, but to no avail.
我在google上尝试了一个建议,但无济于事。
Anyone having a similar issue or know of a work-around?
任何有类似问题或知道解决方法的人?
回答by Warren Benedetto
I know this question is old, but I ran into the same problem. This worked for me:
我知道这个问题很老,但我遇到了同样的问题。这对我有用:
window.open('', '_self', ''); //bug fix
window.close();
回答by Maxim D. Kuznetsov
if previously you open some other window by window.open()
如果之前您通过 window.open() 打开其他窗口
this don't work:
这不起作用:
window.open(...)
window.open('', '_self', '');
window.close();
but work:
但工作:
window.open(...);
setTimeout(function(){
window.open('', '_self', '');
window.close();
}, 100);
回答by Max Kramnik
Something like this should also work:
像这样的事情也应该有效:
setTimeout(function() { window.close(); },50);
setTimeout(function() { window.close(); },50);
回答by nembleton
I think it's working in Chrome Kiosk ( Fullscreen ) mode. Tried successfully.
我认为它在 Chrome Kiosk(全屏)模式下工作。尝试成功。
回答by Ron
top.window.close() works for me. Tested on IE, FF, Chrome, Safari and Opera.
top.window.close() 对我有用。在 IE、FF、Chrome、Safari 和 Opera 上测试。
回答by Gerardo Abdo
This worked for me
这对我有用
var win = window.open("about:blank", "_self"); win.close();
var win = window.open("about:blank", "_self"); 赢。关闭();

