Html4 browsers does not support history.pushState and history.replaceState methods of History API from HTML5

穿精又带淫゛_ 提交于 2019-12-03 08:40:23

I suggest History.js as polyfill for browsers not support History API: https://github.com/browserstate/history.js

It is working in:

HTML5 Browsers:

  • Firefox 4+
  • Chrome 8+
  • Opera 11.5
  • Safari 5.0+
  • Safari iOS 4.3+

HTML4 Browsers:

  • IE 6, 7, 8, 9
  • Firefox 3
  • Opera 10, 11.0
  • Safari 4
  • Safari iOS 4.2, 4.1, 4.0, 3.2

Add jquery.history.js & Register a history.js location handler into you Ember App.

Here are the parts I modified from original Ember.HistoryLocation ( Full code )

(function() {
  var get = Ember.get, set = Ember.set;
  var popstateFired = false;
  Ember.HistoryJsLocation = Ember.Object.extend({
    initState: function() {
      this.replaceState(this.formatURL(this.getURL()));
      set(this, 'history', window.History);
    },
    getState: function() {
      return get(this, 'history').getState().state;
    },
    pushState: function(path) {
      History.pushState({ path: path }, null, path);
    },
    replaceState: function(path) {
      History.replaceState({ path: path }, null, path);
    }
  });
  Ember.Location.registerImplementation('historyJs', Ember.HistoryJsLocation);
})();

Then use this polyfill in your App:

App.Router.reopen({
  location: 'historyJs'
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!