繁体   English   中英

离开我的网站显示带有消息的弹出框

[英]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();

您的行缺少括号()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM