Saturday, December 22, 2012

window.close()/self.close()

You can not close a window unless the window is opened programatically.

No. Basically, only a window that a script opened may be closed by a script. Trying to do so (using the command window.close()) results in the error Scripts may not close windows that were not opened by script.
There is a good reason for this. If any script could close any window, malicious code could easily substitute a fake page for a legit page by loading the fake page in a background window then closing the main window.
Generally speaking, it is bad practice to try and force control of any actions that are usually the domain of your user. This includes things like scroll bars, overall font size, confirmation windows (for printing, saving, closing), and size and state of open windows, etc.

No comments: