最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Alternative to window.close() method for Chrome and Firefox - Stack Overflow

programmeradmin3浏览0评论

I want to close my window/tab when the close button is clicked on the same page.

I used window.close() method. It works perfectly for IE versions, but it doesn't work for Firefox and Chrome.

I searched a lot for a solution. Please give me a demo solution.

I want to close my window/tab when the close button is clicked on the same page.

I used window.close() method. It works perfectly for IE versions, but it doesn't work for Firefox and Chrome.

I searched a lot for a solution. Please give me a demo solution.

Share Improve this question edited Feb 2, 2015 at 15:35 unbindall 5141 gold badge14 silver badges29 bronze badges asked Feb 2, 2015 at 13:56 Sagar BhosaleSagar Bhosale 4051 gold badge5 silver badges19 bronze badges 2
  • Show us the code you are trying that you say doesn't work – StudioTime Commented Feb 2, 2015 at 14:07
  • possible duplicate of window.close and self.close do not close the window in Chrome – Kaiido Commented Feb 2, 2015 at 14:22
Add a ment  | 

1 Answer 1

Reset to default 4

According to MDN

[Window.close()] is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

So in order to use this method, you have to use the window.open() method to be able to close it via window.close().

发布评论

评论列表(0)

  1. 暂无评论