DOM:window.close
From MDC
(Redirected from window.close)
Contents |
[edit] Summary
Closes the current window, or a referenced window.
[edit] Syntax
window.close();
[edit] 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.
[edit] Examples
[edit] 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>
[edit] Closing the current window
<script type="text/javascript">
function closeCurrentWindow()
{
window.close();
}
</script>
[edit] Specification
DOM Level 0. Not part of any standard.