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

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

我尝试使用以下代码在关闭浏览器窗口时收到警报:

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?";}

它有效,但如果页面包含一个超链接,则单击该超链接会引发相同的警报。我只有在关闭浏览器窗口而不是单击超链接时才需要显示警报。


HUWWW
浏览 1533回答 3
3回答

LEATH

保持您的代码不变并使用jQuery来处理链接:$(function () {   $("a").click(function {     window.onbeforeunload = null;   });});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript