The close() method

The close() method is used to close a window. However, you can close only windows opened by you with JavaScript.

Let’s modify the newpage.html and add a button at the bottom so the viewer can close the window.

<body>
<h1>I am an amazing new window<br>
I have been opened with JavaScript.</h1>
<form>
<input type="button" value="Close Window" onclick="window.close();" />
</form>
</body>

Leave a Reply