How to close current tab in a browser window using JavaScript?

In this post we are going to look at the method to close the current tab of the browser window using JavaScript. In earlier time it was possible to close the current tab by using window.close() function. The following syntax was used at that time:

Syntax:

But as per security feature, this syntax has lost its previlege to close the current tab. So you can not simply use window.close() anymore to close the current tab of browser.

A current tab or window can only be closed if it was created by that script. That means window window.close() function is only allowed for the window or tab that has been created and opened using window.open() method.

See below example for the implementation:

So this is how you can easily close current tab in a browser window using JavaScript.

Leave a Reply

Your email address will not be published. Required fields are marked *