我想在网页上创建一个链接,将关闭浏览器中当前活动的选项卡,而不关闭浏览器中的其他选项卡。当用户单击关闭链接时,将出现一条警告消息,要求用户使用“YES”和“NO”两个按钮确认。如果用户单击“是”,关闭该页面,如果“否”,什么都不做。

怎样才能做到呢?有什么建议吗?


当前回答

此方法适用于Chrome和IE:

<a href="blablabla" onclick="setTimeout(function(){var ww = window.open(window.location, '_self'); ww.close(); }, 1000);">
    If you click on this the window will be closed after 1000ms
</a>

其他回答

<button class="closeButton" style="cursor: pointer" onclick="window.close();">Close Window</button>

这对我来说很有效

这是解决这个问题的一种方法,像这样声明一个JavaScript函数

<script>
  function Exit() {
     var x=confirm('Are You sure want to exit:');
     if(x) window.close();
   }
</script>

在HTML中添加以下行,使用<button>调用函数

<button name='closeIt' onClick="Exit()" >Click to exit </Button>

这是可能的。我搜索了整个网络,但有一次当我做微软的一项调查时,我终于得到了答案。

试试这个:

window.top.close();

这将为您关闭当前选项卡。

试试这个

<a href="javascript:window.open('','_self').close();">close</a>

下面是如何创建这样一个链接:

<a href=“javascript:if(“Close window?”)window. Close ()闭> < / a >