Issue with window.close and chrome

二次信任 提交于 2019-11-26 10:44:11

问题


Im trying to close a child window with javascript and in firefox everything works fine but in chrome the window doesnt close

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.

Anyone having a similar issue or know of a work-around?


回答1:


I know this question is old, but I ran into the same problem. This worked for me:

window.open('', '_self', ''); //bug fix
window.close();



回答2:


if previously you open some other window by 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);



回答3:


Something like this should also work:

setTimeout(function() { window.close(); },50);




回答4:


I think it's working in Chrome Kiosk ( Fullscreen ) mode. Tried successfully.




回答5:


top.window.close() works for me. Tested on IE, FF, Chrome, Safari and Opera.




回答6:


This worked for me

var win = window.open("about:blank", "_self"); win.close();



来源:https://stackoverflow.com/questions/2032640/issue-with-window-close-and-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!