Cancelling in beforeunload event handler leaves URL changed
I am using the beforeunload event to get users to confirm that they want to leave my web page (and lose their input). It works fine except for one case: if they try to navigate away by typing a new URL into the address bar, and then cancel, they remain on my page but the address bar still shows their new destination. 

This is harmless but annoying, so I am looking for a way to set the address bar back to my URL, without causing a refresh.

This is my code:

    <script type="text/javascript">jQuery(window).bind('beforeunload', function () {
        return 'This will end your session.';
    });
    </script>
Cancelling in beforeunload event handler leaves URL changed
===

I am using the beforeunload event to get users to confirm that they want to leave my web page (and lose their input). It works fine except for one case: if they try to navigate away by typing a new URL into the address bar, and then cancel, they remain on my page but the address bar still shows their new destination. 

This is harmless but annoying, so I am looking for a way to set the address bar back to my URL, without causing a refresh.

This is my code:

    <script type="text/javascript">jQuery(window).bind('beforeunload', function () {
        return 'This will end your session.';
    });
    </script>