Get the new URL on window.popstate
Asked Answered
B

1

13

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
})
Brunhilda answered 15/9, 2016 at 5:15 Comment(2)
Doesn't location.href work?Feria
window.location.href.toString().split(window.location.host)[‌​1]Monroe
E
23

Use this

window.onpopstate = function (){
    newPageUrl = location.href;
}
Etrem answered 15/9, 2016 at 5:22 Comment(2)
This is the right syntax: window.onpopstate = function() { } developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/…Liability
basically the route-change has registered by the time the event callback is hit. So the currentUrl is the newUrl alreadySparkle

© 2022 - 2024 — McMap. All rights reserved.