Javascript Chrome“脚本可能只关闭由它打开的窗口”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35936011/
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
Chrome “Scripts may close only the windows that were opened by it” error
提问by Keefe
window.close();//false
window.open(location, '_self', '');
window.close();//false
open(location, '_self').close();//false
Chrome 45.0.2454.85 m, Firefox also has the problem.
Chrome 45.0.2454.85 m,Firefox 也有问题。
Please help...
请帮忙...
回答by Roboroads
You should store your opened window in a variable.
您应该将打开的窗口存储在变量中。
var popup = window.open(location, '_blank', '');
popup.close();
EDIT: Opening in _self does not work since you open a new page in the same screen, you might want to do _blank like i've edited.
编辑:在 _self 中打开不起作用,因为您在同一屏幕中打开了一个新页面,您可能想要像我编辑过的那样做 _blank。