window.close and self.close do not close the window in Chrome

后端 未结 16 1793
孤城傲影
孤城傲影 2020-11-21 05:48

The issue is that when I invoke window.close() or self.close() it doesn\'t close the window. Now there seems to be a belief that in Chrome you can\

16条回答
  •  臣服心动
    2020-11-21 06:21

    In my case, the page needed to close, but may have been opened by a link and thus window.close would fail.

    The solution I chose is to issue the window.close, followed by a window.setTimeout that redirects to a different page.

    That way, if window.close succeeds, execution on that page stops, but if it fails, in a second, it will redirect to a different page.

    window.close();
    window.setTimeout(function(){location.href = '/some-page.php';},1000);
    

提交回复
热议问题