How do I close a browser window with HTML code?

Updated: 01/24/2018 by Computer Hope
Close window

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.

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, prompts the user "Do you want to close this window?" If the user clicked OK, the window would close.

<input type="button" value="Close this window" onclick="self.close()">

The second method required a bit more work, but avoided the "prompting issue". The following code may be inserted into the head of an HTML document:

<script language="javascript" type="text/javascript">
function windowClose() {'','_parent','');

Then, the following line of code may be inserted into the body of the HTML document:

<input type="button" value="Close this window" onclick="windowClose();">

Additional information