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

前端 未结 1 871
一生所求
一生所求 2021-02-10 14:44

I am working on an ember application (using ember-1.0.pre.js). And I\'m trying to provide cross browser compatibility on IE8.

The issue is with url generate after every

相关标签:
1条回答
  • 2021-02-10 15:08

    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'
    });
    
    0 讨论(0)
提交回复
热议问题