title: Popup when leaving website
body: <p>I got a problem with JavaScript. 
  I want a script that will pop-up on exit whole web-site a message with question and if visitor answers "NO" web page closes and if he answers "YES" he will be redirected to another page. I found a example at <a href="http://www.pgrs.net/2008/01/30/popup-when-leaving-website/" rel="nofollow">http://www.pgrs.net/2008/01/30/popup-when-leaving-website/</a> but it seems that it doesnt work for me. I couldnt find any solution. 
  Pleae check my code and tell me maybe i'm doing something wrong ?
  Here`s my source code.</p>
  
  <p>Maybe somebody will see a problem. </p>
  
  <pre><code> &lt;!DOCTYPE html&gt;
  &lt;html lang="lt"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;PUA.LT&lt;/title&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
      &lt;meta name="description" content=""&gt;
      &lt;meta name="author" content="Perfect WEB Solutions"&gt;
      &lt;link rel="stylesheet" href="&lt;?php echo base_url("additional/style.css") ?&gt;"&gt;
      &lt;script src='&lt;?php echo base_url("additional/prototype.js")?&gt;' type='text/javascript' &gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script type="text/javascript"&gt;
  
  
  Event.observe(document.body, 'click', function(event) {
    if (Event.element(event).tagName == 'A') {
      staying_in_site = true;
    }
  });
  
  window.onunload = popup;
  
  function popup() {
    if(staying_in_site) {
      return;
    }
    alert('I see you are leaving the site');
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>