Closes the current window, or the window on which it was called.




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 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.


Closing a window opened with

This example demonstrates how to use this method to close a window opened by script calling

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

function openWindow()
  openedWindow ='moreinfo.htm');

function closeOpenedWindow()

Closing the current window

When you call the window object's close() method directly, rather than calling close() on a window instance, the browser will close the frontmost window, whether your script created that window or not.  (Firefox 35.0.1: scripts can not close windows, they had not opened)

<script type="text/javascript">
function closeCurrentWindow()


Specification Status Comment
WHATWG HTML Living Standard
The definition of 'window.close()' in that specification.
Living Standard  

Additional reference

MSDN: window.close Method

Document Tags and Contributors

 Last updated by: maybe,
Hide Sidebar