简体   繁体   中英

window.onpopstate appears to be firing too often

I'm working on this site: http://calebg.me/

To reproduce the issue, click a few links: Projects, Research, Resume, Contact

window.history.length should be 5 .

Pressing the back button will load "/resume.html" as expected. window.history.length is still 5 ..

Pressing back again will reload "/resume.html". window.history.length is still 5 ...

Pressing back one last time will finally properly load "/research.html" as expected. window.history.length is now 4 .

If you continue to press back all the way to the home page, you'll notice that all of the history entries appear to "pop" only after pressing back twice.

Has someone else encountered this that can spot what I've done wrong? You'll find the relevant code inside of the template.js file:

window.onpopstate = function(event) {
    LoadURL(document.location.pathname);
}

I'm almost sure I just need to be using a return true inside that callback or something silly. :P

I was also having same issue, but it is resolved using this reference. Please try below link once,

For resolving popstate on page load

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