How to show modalwindow when user is leaving a webpage?
<p>I have a situation in which i have to stop user from leave webpage, and when user click on X icon or moving away through page, i have to show a modal window with a offer (Image) once user click on image i have to open a special offer page having offer form.</p>

<p>How to achieve this - </p>

<ol>
<li>To prevent from leaving the page?</li>
<li>How to generate a new random url for every click on modal window image, so no one can copy the offer page Url and forward to other users?</li>
</ol>

<p>I have searched in google for preventing the user to go away and found the below code but i dont know how to use it properly. Any direction will be appreciated.</p>

<pre><code>var warning = false;
window.onbeforeunload = function() { 
  if (warning) {
    return 'You have unsaved changes.';
  }
}
</code></pre>

<p>etc on this url: <a href="http://www.kavoir.com/2010/04/javascript-confirmation-warning-before-leaving-or-navigating-away-from-a-page.html" rel="nofollow">JavaScript: Confirmation / Warning before Leaving or Navigating Away from a Page</a></p>

<p>Please help me out, i am a new in php world.</p>
