Close the Current Window Using Javascript

This is a simple tutorial to show you how to close the current browser window with JavaScript.

Steps

  1. To close the browser window, use the windows close() method.
  2. It can be called like so:
    window.close();
  3. Since it is a global method, it can also called like this:
    close();
  4. When this method is called, the browser will ask the user if they want to close the window; and the user can choose to keep the window open.
  5. Use the <script> element to add JavaScript.

Tips

  • Always remember when using this method that the browser will ask if the user wants to keep it open.

Related Articles