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
1 Answer
Reset to default 4According 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()
.