I’ve seen many examples how to ask user if he really wants to leave a currently opened page, but I’ve never seen code that would warn user about leaving a page only if he’s leaving to certain pages, while silently allowing it for other pages.
Basically, I would need a property that gets set to a future page’s href when new url is clicked (or some other event triggers).
From a similar question: How can i get the destination url in javascript onbeforeunload event?
What is possible is to capture the
onbeforeunloadevent. What it is not possible to do is get the url of the page the user is going to. One unorthodox hack is to get the URL of the link last focused on, but that is a infringing on a user’s privacy.