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.

unbindall
  • 514
  • 1
  • 13
  • 29
Sagar Bhosale
  • 407
  • 1
  • 5
  • 19
  • Show us the code you are trying that you say doesn't work – StudioTime Feb 02 '15 at 14:07
  • possible duplicate of [window.close and self.close do not close the window in Chrome](http://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome) – Kaiido Feb 02 '15 at 14:22

1 Answers1

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().

Kaiido
  • 123,334
  • 13
  • 219
  • 285