留下我的网站显示弹出框与消息


leaving my website show popup box with message

当有人试图离开我的网站时,我想向他们显示弹出消息。我尝试使用window.onbeforeunload函数,但它不起作用。

<script language="JavaScript">
  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?";
  }
</script>

嗨,乔纳森,我想在弹出窗口中显示我的自定义消息。目前,它显示默认消息-此页面要求您确认是否要离开-您输入的数据可能无法保存

试试这个。

 $(window).bind('beforeunload', function() {        
        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?";
            }); 

核心的第二行是有缺陷的

应该是:

window.onbeforeunload=confirmExit();

您的行缺少括号()