Custom beforeunload prompt with javascript
<p>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.</p>

<p>Is this possible?</p>

<p>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?</p>

<p><strong>update</strong></p>

<p>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 <code>e.preventDefault();</code> ?</p>

<pre><code>jQuery(window).bind('beforeunload', function() {
    return function () {
        alert('x');

        setTimeout(50000, function () {
            confirm('you sure?');
        });
    }();
});
</code></pre>
