In this section, we will learn what the window close() method is and how to use it in JavaScript.
How to Close a Window? (JavaScript Window close() Method)
If we want to programmatically close a browser window, we can use the `close()` function.
Basically, this method is used to close the current opened window as well as those windows that were opened via calling methods like `open()`.
Note: By default, browsers might not allow you to close a window that we didn’t open programmatically (for example, by the `open()` function).
Window close() Method Syntax:
window.close()
Window close() Method Parameter:
The method does not take an argument.
Window close() Method Return Value:
There’s no return value from calling the method.
Example: close a window in JavaScript
See the Pen close a window in JavaScript by Omid Dehghan (@odchan1) on CodePen.
Note: the `onclick` attribute is an event handler. You’ll learn about event handlers in the future sections.