gpt4 book ai didi

javascript - 仅在关闭选项卡/窗口时弹出确认框

转载 作者:行者123 更新时间:2023-11-30 12:32:05 25 4
gpt4 key购买 nike

您好,我只需要在关闭浏览器/选项卡时弹出确认消息,而不是在单击任何链接时。在我的代码中,当我关闭浏览器/选项卡以及单击任何我不想要的链接时,它会弹出消息。我真的不知道该怎么做。谁能帮帮我吗。我的代码是-

<body>
<div id="copyright">
<div class="moduletable copyright ">


<div class="custom copyright">
<p>
<span class="copy">© Copyright 2008</span>
Inc. All rights reserved. </p>
</div>
</div>
</div>
</div>
</div>
<br class="clear" />
</div>
</div>
<script language="JavaScript">
window.onbeforeunload = bunload;
function bunload(){
dontleave="Are you sure you want to leave?";
return dontleave;
}
</script>
</body>
</html>

最佳答案

试试这个:-

 <body>
<a href="demo-1" onclick="prevent()">click here</a>
<script language="JavaScript">

window.onbeforeunload = function () {
return "Are you sure?";
}
function prevent() {
window.onbeforeunload = function () { };
};

</script>
</body>

关于javascript - 仅在关闭选项卡/窗口时弹出确认框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27395064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com