Is there a way in JavaScript to recognize when a browser is loading a page?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1619930/how-to-check-users-leave-a-page">how to check users leave a page</a>  </p>
</blockquote>



<p>For example when somebody refreshes, enters a new URL into the location bar, or navigates away using a link on the page?</p>

<p>I need to do some work after someone attempts to leave my page.</p>

<p>EDIT: onunload doesn't work because in most browsers that doesn't execute until the page they are attempting to leave to returns a response. I want to execute some code as soon as they attempt to leave.</p>

<p>beforeunload appears to work, but I'm not sure a beforeunload without a return is proper form.</p>
