Does Firefox handle window.onpopstate differently than Chrome and Safari?

老子叫甜甜 提交于 2019-12-11 14:49:28

问题


I've been trying to get a single page application working on Chrome, Safari and Firefox but Firefox doesn't seem to be executing the window.onpopstate at all.

window.onpopstate = function() {
    fullpath = location.pathname;
    console.log(fullpath);
}

I have .htaccess routing all requests back to index.html so when the the client makes a request, the browser stores the url as a javascript variable and passes it through the js in index.html

When run in firefox, the variable isn't passed to the index.html page. Anyone have a solution or any suggestions for how to look deeper into this issue?


回答1:


From the Firefox popstate documentation:

Browsers tend to handle the popstate event differently on page load. Chrome and Safari always emit a popstate event on page load, but Firefox doesn't.

As epascarello says in his comment, initialize your variables in the load event and everything should work in Chrome/Safari and Firefox.



来源:https://stackoverflow.com/questions/16909195/does-firefox-handle-window-onpopstate-differently-than-chrome-and-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!