Window close()
Example
Use open() to open a window and close() to close the window:
let myWindow;
function openWin()
{
myWindow = window.open("", "myWindow", "width=200, height=100");
}
function closeWin()
{
myWindow.close();
}
Try it Yourself »
More examples below.
Description
The close()
method closes a window.
See Also:
Syntax
window.close()
Parameters
NONE |
Return Value
NONE |
More Examples
Example
Open "www.w3schools.com" in a new window, and use close() to close it:
function openWin() {
myWindow = window.open("https://www.w3schools.com", "_blank", "width=200, height=100");
}
function closeWin() {
myWindow.close();
}
Try it Yourself »
Browser Support
close()
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |