title: Exit Popup not working
body: <p>I'm trying to get an exit popup to work. When user closes browser, it asks them if they want to stay or not, and in the background, it starts to redirect already.</p>
  
  <p>This code works in Firefox, but not in Chrome and Opera.</p>
  
  <p>In Chrome, the popup appears but no redirect happens.
  In Opera, the popup doesn't appear at all.</p>
  
  <pre><code>function DisableExitTraffic() {
  PreventExitSplash = true;
  }
  
  function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
      window.onload = func;
  }
  else {
      window.onload = function() {
          if (oldonload) {
              oldonload();
          }
          func();
      }
  }
  }
  function addClickEvent(a, i, func) {
  if (typeof a[i].onclick != 'function') {
      a[i].onclick = func;
  }
  }
  theBody = document.body;
  if (!theBody) {
  theBody = document.getElementById("body");
  if (!theBody) {
      theBody = document.getElementsByTagName("body")[0];
  }
  }
  var PreventExitSplash = false;
  var LightwindowOpening = false;
  function DisplayExitSplash() {
  if (PreventExitSplash == false) {
      window.scrollTo(0, 0);
      window.alert(exitsplashalertmessage);
      PreventExitSplash = true;
      document.location.href = RedirectUrl;
      return exitsplashmessage;
  }
  }
  var a = document.getElementsByTagName('A');
  for (var i = 0; i &lt; a.length; i++) {
  if (a[i].target !== '_blank') {
      addClickEvent(a, i, function() {
          PreventExitSplash = true;
      });
  }
  else {
      addClickEvent(a, i, function() {
          PreventExitSplash = false;
      });
  }
  }
  disablelinksfunc = function() {
  var a = document.getElementsByTagName('A');
  for (var i = 0; i &lt; a.length; i++) {
      if (a[i].target !== '_blank') {
          addClickEvent(a, i, function() {
              PreventExitSplash = true;
          });
      }
      else {
          addClickEvent(a, i, function() {
              PreventExitSplash = false;
          });
      }
  }
  }
  
  addLoadEvent(disablelinksfunc);
  
  disableformsfunc = function() {
  var f = document.getElementsByTagName('form');
  for (var i = 0; i &lt; f.length; i++) {
      if (!f[i].onclick) {
          f[i].onclick = function() {
              if (LightwindowOpening == false) {
                  PreventExitSplash = true;
              }
          }
      }
      else if (!f[i].onsubmit) {
          f[i].onsubmit = function() {
              PreventExitSplash = true;
          }
      }
  }
  }
  addLoadEvent(disableformsfunc);
  window.onbeforeunload = DisplayExitSplash;
  
  var exitsplashalertmessage = '&gt;&gt;&gt; W A I T ! &lt;&lt;&lt;\n\nCongratulations!\nYour IP-address is selected, you could be a winner\n';
  var exitsplashmessage = '&gt;&gt;&gt; CONGRATULATIONS &lt;&lt;&lt;\n\nClick the **CANCEL** button to select your prize!\n';
  var RedirectUrl = 'http://google.com';
  </code></pre>