views:

638

answers:

2
+1  Q: 

Exit survey popup

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.

example: http://www.pgrs.net/2008/1/30/popup-when-leaving-website

There are a couple of issues with this approach:

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.

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.

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.

Thanks.

+1  A: 

You can't solve this problem.

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.

Actually, I would expect all of those things to still fire the onunload, although I'm not 100% sure. I would be surprised if they didn't though.

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.

Yup. Unless you put an immense effort into this, you can't solve it. And what constitutes immense effort? Ever seen gmail? And how it shows you at the bottom everwhere you're logged in from, and the ability to remote kick people off? Something like that, with the pages pinging the server and the server maintaining state and constant communication.

Tom Ritter
The unload does always fire no matter what, you're right. The problem is catching the reload event (meaning the user is still on your domain) as opposed to the case where a user navigates away from the page.
Eysman
+1  A: 

Perhaps not what you were looking for but do users have an account and an email address registered with the site?

If they have left the site via means you cannot detect (say, closing the browser,) you could email them an invitation to complete the survey.

Seth