为了账号安全,请及时绑定邮箱和手机立即绑定

如何防止关闭浏览器窗口?

如何防止关闭浏览器窗口?

HUWWW 2019-08-19 11:02:48
如何防止关闭浏览器窗口?我尝试使用以下代码在关闭浏览器窗口时收到警报:window.onbeforeunload = confirmExit;function confirmExit() {   return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";}它有效,但如果页面包含一个超链接,则单击该超链接会引发相同的警报。我只有在关闭浏览器窗口而不是单击超链接时才需要显示警报。
查看完整描述

3 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

保持您的代码不变并使用jQuery来处理链接:

$(function () {
  $("a").click(function {
    window.onbeforeunload = null;
  });});


查看完整回答
反对 回复 2019-08-19
  • 3 回答
  • 0 关注
  • 1531 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号