Window close() method
- Previous page clearTimeout()
- Next page closed
- Go back to the previous level Window Object
Example
Example 1
Open a window using open() and close it using close():
let myWindow; function openWin() { myWindow = window.open("", "myWindow", "width=200, height=100"); } function closeWin() { myWindow.close(); }
Example 2
Open "www.codew3c.com" in a new window and close it using close():
function openWin() { myWindow = window.open("", "_blank", "width=200, height=100"); } function closeWin() { myWindow.close(); }
Syntax
window.close()
Parameter
None.
Return value
None.
description
method close()
will close the top-level browser window specified by window. self.close()
or simply call close()
to close itself.
Only windows opened by JavaScript code can be closed by JavaScript code. This prevents malicious scripts from terminating the user's browser.
Browser support
All browsers support close()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous page clearTimeout()
- Next page closed
- Go back to the previous level Window Object