Close the Current Window Using Javascript
This is a simple tutorial to show you how to close the current browser window with JavaScript.
Steps
- To close the browser window, use the windows close() method.
- It can be called like so:
window.close(); - Since it is a global method, it can also called like this:
close(); - 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.
- 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.