问题
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