Latest web development tutorials
 

Window close() Method

< Window Object

Example

Use open() to open a new window, and close() to close the new window:

function openWin() {
    myWindow = window.open("", "myWindow", "width=200, height=100");   // Opens a new window
}

function closeWin() {
    myWindow.close();   // Closes the new window
}
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The close() method closes the current window.

Tip: This method is often used together with the open() method.


Browser Support

Method
close() Yes Yes Yes Yes Yes

Syntax

window.close()

Parameters

None

Technical Details

Return Value: No return value

Examples

More Examples

Example

Open "www.w3ii.com" in a new window, and use close() to close the window:

function openWin() {
    myWindow = window.open("http://www.w3ii.com", "_blank", "width=200, height=100");
}

function closeWin() {
    myWindow.close();
}
Try it Yourself »

< Window Object