title: Exit survey popup
body: <p>I'm trying to create an exit popup to conduct an exit survey for a site I'm working on. 
  The most common solution I've come across is to catch the page onunload event, and add an event handler to all link click events to block the popup.</p>
  
  <p>example: <a href="http://www.pgrs.net/2008/1/30/popup-when-leaving-website" rel="nofollow noreferrer">http://www.pgrs.net/2008/1/30/popup-when-leaving-website</a></p>
  
  <p>There are a couple of issues with this approach:</p>
  
  <p>First, you will not be able to detect events such as a page refresh or a manual URL change, since it's a browser event and not a page event. </p>
  
  <p>Secondly, if the user has multiple tabs open and closes one, it's impossible to tell that the user is still on the site. Even if we use cookies to keep track of number of windows open, we won't know if the user is actually leaving the website, or just going to an internal link.</p>
  
  <p>I feel like the best solution I could implement is a combination of overriding all events and keeping track of windows open in a cookie, but I'm wondering if anyone has come up with a better method.</p>