Reputation: 407
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.
Upvotes: 0
Views: 11040
Reputation: 136638
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()
.
Upvotes: 4