View Full Version : Onunload (use with a trigger?!)

07-21-2009, 03:46 PM
Hi All,

I have a div overlay which presents a survey entry page to users, currently using a timed delay but wanting to add functionality to give the option to load the survey on page exit.

I can get it to load at page exit (using onunload) but a split second later the next page loads and the survey disappears (as its a div overlay and not a popup).

Is there any way I can basically tell the onunload to hold off loading the new page - perhaps waiting for a trigger from the div overlay (saying yes or no to the taking part in the survey?) - So then when you press yes or no it will then load the new page?

Any ideas?


07-22-2009, 02:21 AM
Now that's not very nice, is it? If I were your user, I'd hate you for making me tell you that I don't want to take your survey before you let me leave your site.

Anyway, what you can do is use the unbeforeunload event to show the survey and return false. If you're lucky, the browser will ask the user then if she really wants to leave your site.