title: Stop showing confirm box upon page reload - Javascript
body: <p>I want to ask for a confirmation to the user when they are leaving a page.</p>
  
  <p>I know it can be achieved very easily using javascipt's <strong>window.onbeforeunload</strong></p>
  
  <p>But the only issue is, it shows a pop up(see picture) when I reload the page. I don't want to display that pop up upon page reload. I think that pop-up is displaying by the web browser as it shows a message "Do you want to reload this site?" which I have not written anywhere.</p>
  
  <p>Here is my simple code:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Script&lt;/title&gt;
          &lt;script&gt;
              window.onbeforeunload = function () {
                  return 'Are you sure you want to leave?';
              };
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          hello
          &lt;a href="http://google.com"&gt;Google&lt;/a&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DgAV6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DgAV6.png" alt="enter image description here"></a></p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Lots of people saying that it is bad to ask user while he is leaving the site and I'm also <strong>completely</strong> agreed with that. But it is client's requirement, so it is not up to me. Sorry for that.</p>
  
  <p>Thanks,</p>
  
  <p>Parth vora</p>