【问题标题】:How to detect 'leave' button on window.onbeforeunload js php如何检测window.onbeforeunload js php上的“离开”按钮
【发布时间】:2017-12-08 20:43:32
【问题描述】:

我正在为我的项目开发一个简单的 LMS 系统。如果用户离开当前考试页面,下面的代码将阻止用户,如果用户想离开页面,它将弹出 js 消息(有 2 个按钮离开和停留)

comfirmExit

<script type="text/javascript">
  var hook = true;
  window.onbeforeunload = function() {
    if (hook) {
      return "You have attempted to leave this page. Are you sure?";
   //if leave --> markzero.php
   //else stay --> do nothing
    }
  }
  function unhook() {
    hook=false;
  }
</script> 

我想在这里实现的是 - 如果用户单击“离开”,则标记将显示为 0。我不确定如何检测该“离开”按钮。

【问题讨论】:

    标签: javascript php jquery ajax


    【解决方案1】:

    试试这个-

    <script type="text/javascript" language="javascript">
                   window.onbeforeunload = function() {
                       var Ans = confirm("You have attempted to leave this page. Are you sure?");
                       if(Ans==true)
                           return true;
                       else
                           return false;
                   };
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      相关资源
      最近更新 更多