Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 确认导航不显示我的信息_Javascript_Dom - Fatal编程技术网

Javascript 确认导航不显示我的信息

Javascript 确认导航不显示我的信息,javascript,dom,Javascript,Dom,我用过这个,但它没有显示我的自定义消息,而是显示它自己的消息 <script language="JavaScript"> var needToConfirm = true; window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) return "You have attempted to leave this page. If you

我用过这个,但它没有显示我的自定义消息,而是显示它自己的消息

<script language="JavaScript">


 var needToConfirm = true;

  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    if (needToConfirm)
      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>

var needToConfirm=true;
window.onbeforeunload=确认退出;
函数confirmExit()
{
如果(需要确认)
return“您试图离开此页面。如果您在未单击“保存”按钮的情况下对字段进行了任何更改,您所做的更改将丢失。是否确实要退出此页面?”;
}

自定义消息将仅在Google chrome中显示,Firefox目前不支持该消息。

尝试使用alert而不是return