JavaScript Window close() method

The close() method in JavaScript is used to close a window that was previously opened using the method. This method does not take any arguments, and simply closes the window on which the close() method is called.

Here is an example of how the close() method works:

const myWindow ='', 'my-window', 'width=800, height=600');


// this will close the window that was opened with the '' method

In the code example above, we first use the method to open a new window and navigate to the Google homepage. We store the new window in the myWindow variable.

We then use the close() method to close the myWindow window. The close() method does not take any arguments, so we simply call the method on the myWindow window without passing any arguments.

As a result of calling the close() method, the myWindow window will be closed. If the myWindow window was already closed, calling the close() method will have no effect.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: