1

私のアプリケーションの 1 つで、window.history.pushState()メソッドを使用してウィンドウの URL を更新します。しかし、IE < 10HTML5 の履歴 API をサポートしていないため、代替手段を探していました。SOに関する他の多くの質問への回答は、history.jsプラグインの使用を提案しています。

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);
}
4

1 に答える 1

0

機能させるには、履歴変数と状態変数を初期化する必要があります。

(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')
于 2013-10-29T11:41:21.513 に答える