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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:23:31  来源:igfitidea点击:

Chrome “Scripts may close only the windows that were opened by it” error

javascript

提问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...

请帮忙...

Console option screenshot

控制台选项截图

回答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。