在 IE7 中使用 Backbone.js 基于哈希的导航
我正在构建一个带有基于哈希的导航的 Backbone.js 应用程序。除了 IE7 之外,它在任何地方都可以正常工作。在 IE7 中,当我单击更改哈希值的链接时,会发生的情况是:
- 页面更改
- 哈希值,然后恢复到以前的值
- 页面也更改到上一页
我通过添加 saveLocation< /code> 在加载每个页面后调用控制器,但是当我使用后退按钮或重新加载页面时,它总是将我带到主页,而不是返回或重新加载当前页面。
我该怎么做才能使后退按钮和页面重新加载正常工作?
I'm building a Backbone.js app with hash based navigation. It works fine everywhere except IE7. In IE7, when I click on a link that changes the hash, what happens is:
- the page changes
- the hash then reverts to the previous value
- the page changes to the previous page as well
I made the links work by adding saveLocation
calls to the controller after loading each page, however when I use the back button or reload the page, it always takes me to the home page instead of going back or reloading the current page.
What can I do to make the back button and page reloading work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对主干做了一些更改,使其适合我。您可以在这里查看我的存储库:
https://github.com/juggy/backbone
适用于到目前为止我。我不知道我是否破坏了其他东西。我从 YUI 和 https://github.com 中获得灵感/cowboy/jquery-hashchange/blob/master/jquery.ba-hashchange.js 。
I made some changes to backbone to make it work for me. You can have a look at my repo here:
https://github.com/juggy/backbone
Works for me so far. I dunno if I broke anything else. I inspired myself from YUI and https://github.com/cowboy/jquery-hashchange/blob/master/jquery.ba-hashchange.js .
我也遇到了与你相同的 IE7 问题,并尝试了各种方法(saveLocation、Backbone 补丁等)..但没有成功。看来IE7在切换多个页面时会产生误解。
我的最终解决方案是不使用 Backbone.history 而是使用 jQuery History Plugin。
http://tkyk.github.com/jquery-history-plugin/
我知道这是最糟糕的解决方法,因为该解决方案依赖于其他插件,但幸运的是,Backbone.Controller 仅处理路由和状态处理,您不必使用它。
jQuery 历史记录插件可以正常工作。
I also had same IE7 problem with you, and tried every way (saveLocation things, Backbone patches, etc).. but it didn't work out. It seems IE7 misunderstand when switching thru many pages.
My final solution was not to use Backbone.history but jQuery History Plugin.
http://tkyk.github.com/jquery-history-plugin/
I know this is the worst workaround because this solution relies on other plugin, but fortunately, Backbone.Controller just handles routings and state handling that you don't have to use it.
jQuery History Plugin just works.
答案已发布在 Backbone.js 仅在 IE7 中导致错误 。
An answer has been posted in Backbone.js cause bug only in IE7.