2013-10-28 46 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