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

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

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

  • 1 个回答
  • 4 人有此问题
  • 13 次查看
  • 最后回复者为 cor-el

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(); }

所有回复 (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.