Created
August 4, 2012 18:45
-
-
Save johnkpaul/3259269 to your computer and use it in GitHub Desktop.
IE9- and Backbone.history's pushState
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//in your application, rather than using window.location to get the current url | |
App.getLocation = function(){ | |
return window.location.protocol + '//' + window.location.host | |
+ '/' + Backbone.history.options.root + Backbone.history.getFragment() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//when your application starts up | |
Backbone.history.start({ pushState: Modernizr.history, silent: true }); | |
if(!Modernizr.history) { | |
var rootLength = Backbone.history.options.root.length; | |
var fragment = window.location.pathname.substr(rootLength); | |
Backbone.history.navigate(fragment, { trigger: true }); | |
} else { | |
Backbone.history.loadUrl(Backbone.history.getFragment()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Класс! писал свой костыль, вышло на 300+ строк... Вставил твой - заработало!
вот только Modernizr.history заменил на:
function if_history() {
return !!(window.history && window.history.pushState);
}
Как это работает можешь глянуть на http://lavrik-v.ru/
Спасибо!