Is there any way to get the URL written with location.href into window.onbeforeunload function?
I want to include some 3rd party js into my website. Some of them might have redirection code inside of it something like this:
location.href="http://example.com";
So, it will cause a redirection to their website when user try to open my website. So I just want to prevent it. I can do that using:
window.onbeforeunload = function () {
// Here I want to get the URL where user is going to be redirect
// If that URL is a 3rd party website, I will return false
return false;
}
As per my knowledge, it is something like impossible.
Any help would be appreciated.
PS: I already checked this: How can i get the destination url in javascript onbeforeunload event?
So here simply, I just want to prevent such automated 3rd party redirection. Is there any code/tool/script available for that?
Thanks, Parth vora