Can I get the updated URL before the page unloads.
I'd like to check if this URL is still the URL being used by the user during a refresh.I'd like to do something before the user changes to another page.
usecase:
[Normal] browser address bar: www.mypage.com/page1.html user clicks reload NO popup notification display Page reloads
[Abnormal] browser address bar: www.mypage.com/page1.html user modifies address bar: www.anotherpage.com POP UP notification displays before www.anotherpage.com is loaded
I'd like to know how to get the current value of the address bar before the page unloads I tried this code snippet:
var currPage;
window.onload = function(){
currPage = document.location.href;
}
window.onbeforeunload = function (e){
var nextLocation = document.location.href; // I assumed this value will update always. but NOT! :((
if( currPage != nextLocation )
{
alert("You're leaving now??!");
}
}
Please help me.