如何防止关闭浏览器窗口?我尝试使用以下代码在关闭浏览器窗口时收到警报: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; });});
添加回答
举报
0/150
提交
取消