26

有没有办法pushState在 IE9 中使用 HTML5 History API ( )?如果有适用于所有其他浏览器的解决方案,那就太好了!

4

2 回答 2

26

历史.js

从回购报价:

History.js 在所有浏览器中优雅地支持 HTML5 History/State API(pushState、replaceState、onPopState)。包括对数据、标题、replaceState 的持续支持。支持 jQuery、MooTools 和原型。对于 HTML5 浏览器,这意味着您可以直接修改 URL,而无需再使用哈希。对于 HTML4 浏览器,它将恢复使用旧的 onhashchange 功能。

于 2011-04-03T04:45:58.847 回答
-1

根据有关历史 API 的 Ember 文档:http: //emberjs.com/api/classes/Ember.Location.html

支持历史 API 的浏览器将使用 HistoryLocation,那些不支持但仍支持 hashchange 事件的浏览器将使用 HashLocation,在极少数情况下都不支持将使用 NoneLocation。

App.Router.map(function() {
  this.resource('posts', function() {
    this.route('new');
  });
});

App.Router.reopen({
  location: 'auto'
});

对于支持历史 API 的现代浏览器,这将导致一个 posts.new url 为 /posts/new,对于较旧的浏览器,如 Internet Explorer 9 及更低版本,则为 /#/posts/new。

当用户访问指向您的应用程序的链接时,他们将自动升级或降级到适当的 Location 类,并在需要时相应地转换 URL。

于 2014-07-14T10:23:13.680 回答