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.
Definition and Usage
The close()
method closes a window.
Se 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 | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |