title: Detect via js a browser window/tab close event
body: <p>I'm trying to detect if a user is leaving my websites. Like a window/tab close event of the webbrowser or by following a link to a other domain.</p>
  
  <p>In some searches I found some solutions, but they alert ever when a link is clicked, also on my pages. As example I tried out this:</p>
  
  <pre><code>window.onbeforeunload = function(event) {
  
  event = event || window.event;
  
  var confirmClose = 'Are you sure?';
  
  // For IE and Firefox prior to version 4
  if (event) {
     event.returnValue = confirmClose;
  }
  
  // For Safari
  return confirmClose;
  
  }
  </code></pre>
  
  <p>So what do I have to modify so that the alert is deactivated when I'm browsing through my domain?</p>
  
  <p>Thanks
  Oliver</p>