title: window.onbeforeunload runs only when closing window not on refresh
body: <p>I have this function </p>
  
  <pre><code> window.onbeforeunload = function () {        
            return "Are you sure?";        
      };
  </code></pre>
  
  <p>and I have a button that when the user presses it the window refreshes to update screen values and do some database calls. I added <code>window.onbeforeunload=null;</code> in the beginning of the function to disable onbeforeunload but it kept being called.</p>
  
  <p>Is there a way to either disable the onbeforeunload function in my button onclick function or make the window.onbeforeunload get called only on close window not on refresh?</p>