当用户使用JavaScript单击按钮时,如何关闭当前浏览器选项卡?

时间:2015-11-10 10:15:03

标签: javascript jquery html html5 javascript-events

在一个页面中,我有一个'关闭'单击时必须关闭当前浏览器选项卡的按钮(其中包含此关闭按钮的页面的选项卡)。所以我写了这样的话:

<button type="button" class="btn btn-default" style="color: #0F8BB0;" onclick="window.close();">
    Close
</button>

但它不起作用且当前的浏览器标签未关闭。为什么?我错过了什么?我该如何尝试解决这个问题?

1 个答案:

答案 0 :(得分:2)

您正确地执行了此操作,但是如果您的javascript没有创建它,则浏览器会阻止您关闭窗口。

所以基本上只有在通过javascript打开该窗口时才能关闭窗口。

另见:window.close and self.close do not close the window in Chrome

相关问题