title: How to detect 'leave' button on window.onbeforeunload js php
body: <p>I'm developing a simple LMS system for my project. The code below will block user if they leave the current exam page and it will pop out js message if user wants to leave the page (has 2 button leave and stay)</p>
  
  <p><a href="https://i.stack.imgur.com/zByrd.png" rel="nofollow noreferrer">comfirmExit</a></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var hook = true;
    window.onbeforeunload = function() {
      if (hook) {
        return "You have attempted to leave this page. Are you sure?";
     //if leave --&gt; markzero.php
     //else stay --&gt; do nothing
      }
    }
    function unhook() {
      hook=false;
    }
  &lt;/script&gt; 
  </code></pre>
  
  <p>What I want to implement here is that - if user click 'leave' the mark will be given as 0. I'm not sure how to detect that 'leave' button.</p>