views:

20

answers:

3

I'm trying to setup an exit survey so that when a user leaves our checkout page they are prompted asking them why they're leaving.

Is this possible?

I've spent some time on Google but it appears as though the only solution is a simple browser-controlled confirm-like prompt. Is this true?

update

The following confirm dialog never appears, the page just changes or exits. How can I prevent the page from changing/exiting until I wait for a user's response. I guess I should ask, how can I resume a user's exit/page change action after using e.preventDefault(); ?

jQuery(window).bind('beforeunload', function() {
    return function () {
        alert('x');

        setTimeout(50000, function () {
            confirm('you sure?');
        });
    }();
});
A: 

You can do anything you want in the onunload event of the browser:

body.onunload = function() {
  foo();
  bar();
}
levu
A: 

If you are using jQuery you can just do

$(window).unload( function() {
  //statements
});
Robusto
A: 

As suggested by levu, use the onunload event in combination with a custom modal dialog, such as thickbox - http://jquery.com/demo/thickbox/

Josh