Whenever I add an event listener window.onbeforeunload, can I check where the page is being redirected to?
Or at least what the developer is trying to change.
The following is the thing that I really want:
This is what I do right now :
$(window).bind("beforeunload",function(){
//I do what I want here
});
Now the issue is, I want to change the logic, when document.location.href = "mailTo:*" is being called. i.e. I do not want to do anything when doccument.location.href is called, so I want my logic to me like:
$(window).bind("beforeunload",function(){
if(document.location.href has mailTo:)
{
//do nothing
}
else
{
//my old logic applies here
}
});
You would need to add an event handler to Href links in your webpage,
which set a variable on onclick = their href, you can read that variable in your onbeforeunload script. example code would be like this :
However if the redirection is happening due to some other event,like user entering a new url in the browser, or using a script, you can not detect the destination due to security reasons.
Similar:
How can i get the destination url in javascript onbeforeunload event?