2013-10-28 94 views
1

在我的一個應用程序中,我使用window.history.pushState()方法來更新窗口URL。但是,由於IE < 10不支持HTML5的歷史API,我正在尋找替代方案。 SO上的很多其他問題的答案建議使用history.js插件。使用history.js與IE9

從history.js插件提供的文檔中,它的用法並不十分清楚。我已經加入了插件的<head></head>節在我的模板,但在IE9我仍然接受,說的錯誤:

SCRIPT438: Object doesn't support property or method 'pushState' 
params.js, line 37 character 5 

的錯誤出如下

/** 
* updates the window url according to the given parameters. 
*/ 
function updateUrl(params) { 
    var path = window.location.pathname; 
    var url = $.param.querystring(path, params); 
    url = decodeURIComponent(new_url).replace("#", "", "g"); 
    window.history.pushState(null, null, new_url); 
} 

回答

0

您需要initiatialize功能歷史和狀態變量的工作。

(function(window, undefined) { 
    // Define variables 
    var History = window.History, 
     State = History.getState(); 

    // Bind statechange event 
    History.Adapter.bind(window, 'statechange', function() { 
     var State = History.getState(); 
    }); 
})(window) 

,現在你可以使用pushState方法對於所有瀏覽器如下:

History.pushState(null, null, '?your=hash') 
+2

你是在用結合「的window.history」而不是「window.history的」與history.js。與初始化無關=) – Dave