javascript 在 IE9 中使用 HTML5 pushState()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5527617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:30:43  来源:igfitidea点击:

Using HTML5 pushState() in IE9

javascripthtmlpushstate

提问by Mohsen

Is there any way to use HTML5 History API (pushState) in IE9? If there is a solution for all other browsers that would be great!

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

采纳答案by amosrivera

History.js

历史.js

Quote from the repo:

来自回购的报价:

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

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

回答by borisrorsvort

As per Ember documentation about history api: http://emberjs.com/api/classes/Ember.Location.html

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

Browsers that support the history API will use HistoryLocation, those that do not, but still support the hashchange event will use HashLocation, and in the rare case neither is supported will use NoneLocation.

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

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

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

This will result in a posts.new url of /posts/new for modern browsers that support the history api or /#/posts/new for older ones, like Internet Explorer 9 and below.

对于支持历史 API 的现代浏览器,这将导致 /posts/new 的 posts.new url 或旧浏览器的 /#/posts/new 网址,例如 Internet Explorer 9 及更低版本。

When a user visits a link to your application, they will be automatically upgraded or downgraded to the appropriate Location class, with the URL transformed accordingly, if needed.

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