Mozilla's getting a new look. What do you think? https://mzl.la/brandsurvey

window.close Redirect 1

« DOM Reference

Summary

Closes the current window, or a referenced window.

Syntax

window.close();

Description

When this method is called, the referenced window is closed.

This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

Examples

Closing a window opened with window.open()

<script type="text/javascript">
//Global var to store a reference to the opened window
var openedWindow;

function openWindow()
{
  openedWindow = window.open('moreinfo.htm');
}
function closeOpenedWindow()
{
  openedWindow.close();
}
</script>

Closing the current window

<script type="text/javascript">
function closeCurrentWindow()
{
  window.close();
}
</script>

Specification

DOM Level 0. Not part of any standard.

Additional Reference

MSDN: window.close Method

Document Tags and Contributors

 Last updated by: Sheppy,