For historical reasons, this page lists methods that were formerly used to programmatically close a browser tab or window using JavaScript.
Closing a window with JavaScript: two former methods
The first method created a button that, when clicked, prompted the user “Do you want to close this window?” If the user clicked OK, the browser tab or window closed.
As of 2017, there is no way to close a web browser tab or window using JavaScript. Modern security standards do not permit this behavior. The JavaScript code below does not work anymore and is purely for educational purposes.
The second method required a bit more work, but avoided the “prompting issue”. The following code was inserted in the head of an HTML page.
Then, the following line of code was inserted in the body of the HTML page.
Related information
- See our close and window definitions for further information and related links.
- HTML and web design help and support.