0

Is it possible to automatically close a web browser window (e. g., in Google Chrome) when the user clicks outside the window? In order to do this, there would need to be some method for detecting whether or not the window was focused, and also a method for closing the window.

Anderson Green
  • 30,230
  • 67
  • 195
  • 328

2 Answers2

1

Most current browsers only let you close the child windows of a parent.
You can't close the master parent window through a script.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
0

By default most browsers do not allow javascript to close windows that were not opened by javascript itself. But if you use e.g. window.open(...) you can close that window with window.close().

So if you have a window opened by javascript you can do the following:

window.addEventListener('blur', function(){window.close();}, false);
AmShaegar
  • 1,491
  • 9
  • 18