2017-03-27 20 views
0

以下のコードでは、選択した要素をすべて配列にプッシュします。 window.location.hrefのようなjavascriptを使ってURLパラメータにプッシュすることができます。ページのリロード/リダイレクトなしでurlにparamsを追加できますか?ページをリロードしないでurlにparamsを追加(取得)しますか?

var keys = []; 
keys.push({selected_element:object.key}); 

必要な構造は次のとおりです。/index.php?element[]=546454&element[]=156151&element[]=343141

+0

http://stackoverflow.com/questions/824349/modify-the-url-ページを再ロードせずに http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page – NullDev

答えて

3

あなたはhistory.pushStateを使用することができます...:

if (history.pushState) 
{ 
    var newQueryString = window.location.protocol + "//" + 
    window.location.host + window.location.pathname + 
    '?newStuff[]=123&whatever=909'; 

    window.history.pushState({path:newQueryString},'',newQueryString); 
} 
+0

これは私のものです欲しい、ありがとう! –

+0

@ user2956944喜んでお手伝いします - あなたの質問に答えた場合、受け入れられた回答としてチックを行う - 歓声 – Stuart

関連する問題