简体   繁体   中英

Browser's Back & Forward Buttons Don't Work After History.pushState()

I have a simple history.pushState() in my code:

history.pushState(null,null,data["url"]);

And it works perfectly, but when I click the browser's back button after running history.pushState() , only the URL bar changes; the page it's self does not reload.

I reviewed several StackOverflow questions where this problem had been presented but none of the solutions in these answers solved my problem. I do not have any other history calls in my code, but for an identical call elsewhere. I'm not using window.onpopstate either and would prefer not to, unless absolutely necessary.

I noticed that in this answer , the author suggested checking the address bar for changed every 500ms, then loading new content. This seems like a rather in-elegant solution and, though I would if there is no other way, I'd prefer not to use it (I'm worried about the effect it might have on performance).

Well, for start - why not using onpopstate?* this is the right way to do it, as far as I understand.

_

*or, bind('popstate')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM