javascript - Disable Backbone.js hashes entirely, but keep pushState in History? - Stack Overflow

I'd like to use Backbone's fantastic routing system, but I'd like to NOT have any form o

I'd like to use Backbone's fantastic routing system, but I'd like to NOT have any form of hash support for older browsers. Is it possible to disable hashes entirely when using pushState in Backbone.History?

I'd like to use Backbone's fantastic routing system, but I'd like to NOT have any form of hash support for older browsers. Is it possible to disable hashes entirely when using pushState in Backbone.History?

Share Improve this question asked Mar 3, 2012 at 0:50 CarsonCarson 17.8k21 gold badges75 silver badges88 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

It's not documented on the backbone.js page, but I found it in the annotated source. If you pass hashChange false to Backbone.history.start(), backbone will not use the hash fallback.

EG:

Backbone.history.start({hashChange:false, pushState:true})

There's lots of good reasons to support pushState, and not fall back to use of hashes, all while still supporting older browsers (the browser will go to the new url and reload instead of updating with ajax).

There's no built in support for this, if it's important to your app to not work in older browsers you could probably modify your version of Backbone. You could just add something like the following at the start of your DomReady function:

if (window.history && window.history.pushState) {
     // main script
} else {
     alert("Your browser doesn't support push state and I don't want backwards patibility");
     window.location('http://away.from.here');
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745249596a4618597.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信