Hcabnettek
Hcabnettek

Reputation: 12928

In window.beforeunload, how do you capture the url they are trying to navigate to?

I'm trying to capture some data on window.beforeunload:

window.onbeforeunload = function () {
        var newLocation = location.href;
        promise = doAjaxStuff

        promise.done(function () {
            //navigate to new location or close browser
            console.log(newLocation);
        });


    };

How can I get the Url of the link etc... they wish to nav to? Including browser back and next.Also if they close the browser, I'd like my call to succeed then close the browser. Is this possible? This functions use is if you return a string it will open a confirm close dialog etc... I want similar behavior without the dialog basically. Any links, code, tips, or tricks are always welcomed.

Upvotes: 0

Views: 722

Answers (1)

SLaks
SLaks

Reputation: 887469

This will never be possible, for privacy reasons.

It would be a very bad idea to allow websites to find out where the user is going next.

Upvotes: 2

Related Questions