In earlier versions, I used to test if I should be triggering popstate
manually on page load, because Chrome triggers it right after load, and Firefox and IE do not.
if ($.browser.mozilla || $.browser.msie) {
$(window).trigger('popstate');
}
Now that they dropped the browser object in 1.9, how should I test for these browsers? Or how do I figure if I need to popstate
on page load or not?
The code is:
$(function(){
$(window).on('popstate', popState);
// manual trigger loads template by URL in FF/IE.
if ($.browser.mozilla || $.browser.msie) {
$(window).trigger('popstate');
}
});
Update
Went for this:
function popState(e){
var initial = e.originalEvent === undefined || e.originalEvent.state === null;
if(!initial){
activateRoute({
key: e.originalEvent.state.key,
settings: e.originalEvent.state.settings
},'replace');
}
}
function init(){
$(window).on('popstate', popState);
$(function(){
var route = getRoute(document.location.pathname);
activateRoute(route, 'replace');
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…