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.

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

Leave a Reply