Get the new URL on window.popstate

user6459745 picture user6459745 · Sep 15, 2016 · Viewed 7.3k times · Source

Is there any way I can get the new page's url when the window.popstate is fired?

window.onpopstate(function (){
    newPageUrl = //get the new page's URL
})

Answer

KANAYO AUGUSTIN UG picture KANAYO AUGUSTIN UG · Sep 15, 2016

Use this

window.onpopstate(function (){
    newPageUrl = location.href;
})