Windows 10 reached EOS (end of support) on October 14, 2025. If you are on Windows 10, see this article.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More
Archyvinta

How to close a tab using javascript? window.close() doesnt work here.

cor-el replied
harshitgor

I am using the following function to close current tab.

function closeWindow() {
           window.open("", "_self");
           window.close(); 
       }
I am using the following function to close current tab. function closeWindow() { window.open("", "_self"); window.close(); }

All Replies (1)

You can only close windows that way that are opened via window.open()

This method is only allowed to be called for windows that were opened by a script using the window.open() 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.