title: when unload or exit event execute a function jQuery
body: <p>I have a customize pop up box like a lightbox or a modal box and I want to show it and prevent the page from unloading or exit when a user tries to leave or exit the page so heres my code and my try so far:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>$(window).bind('beforeunload', function(){
    return loadPopup();
  });
  </code></pre>
  
  <p>As you can see from the above codes, when a user tries to exit or leave the page, it should execute a function:</p>
  
  <pre class="lang-js prettyprint-override"><code>loadPopup();
  </code></pre>
  
  <p>But it does not work, the <code>loadPopup();</code> doesn't fired. What supposed to be a problem on my above codes why it doesnt execute the <code>loadPopup();</code> function?  </p>