You are here: Reference > JavaScript > client-side > dialog > methods > close (window)

close method (window)

Browser support:
Closes the current window.
The close method behaves differently in different browsers.
  • In Opera, Google Chrome and Safari, it always closes the current window.
  • In Internet Explorer, if the current window was opened by a script and it is not the last running instance of Internet Explorer, then the close method closes the window, else it displays a confirmation dialog.
  • In Firefox, if the current window was opened by a script, the close method closes the window, else it does not.

Syntax:

object.close ( );
You can find the related objects in the Supported by objects section below.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the close method:
<head>
    <script type="text/javascript">
        function Open () {
            window.open (window.location.href, "_blank", "width=350, height=250, left=10, top=10");
        }
        function Close () {
            window.close ();
        }
    </script>
</head>
<body>
    <button onclick="Open ();">Open a new window</button>
    <button onclick="Close ();">Close the current window</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content