2016-10-21 26 views
0

有沒有加載html文件的方法,並且在頁面加載時將參數傳遞給url?通過添加參數的URL加載html

可以說一個應用程序加載index.html。有沒有辦法使URL變成index.html?locale = ru而不是index.html?

當然,這很容易,如果你可以點擊從某處,但我希望參數被添加到URL「onload」。

我在想這樣的事情也許:

window.onload = function() { 
    window.location.href= '?parameter1&parameter2' 
} 
+0

如果你做這種方式,它會不斷重裝,嘗試添加類似的東西'如果(window.location.href.indexOf(「?parameter1&parameter2」)== -1)' – JohannesB

+1

您最好解釋一下將查詢字符串附加到當前URL的預期行爲是什麼?你爲什麼需要這個? [歷史API](https://developer.mozilla.org/en-US/docs/Web/API/History_API)可能是你正在尋找的,但我有疑問... –

+0

@ A.Wolff什麼我需要爲app加載index.html?parameter1而不是index.html。原因是應用程序使用元數據,並將用戶帶到特定的位置。 – Monduiz

回答

0

這完美的作品:

window.location.replace("index.html#parameter1#parameter2");