2013-04-10 107 views
2

我想用JavaScript來刷新網頁,並且,我知道怎麼做,但我有一個問題, 刷新前:如何使用javascript刷新網頁?

網址

http://www.example.com/index.html#introduction

刷新後:

網址:http://www.example.com/index.html

我想在頁面刷新後使用該散列作爲另一個JavaScript函數中的參數。

那麼,如何在頁面重新加載後保存散列?

+0

您是否使用任何服務器端語言? – Sandeep 2013-04-10 07:34:54

+0

你是如何刷新頁面的?請顯示代碼! – 2013-04-10 07:35:32

+0

不適用,僅限javascript。 – fronthem 2013-04-10 07:35:48

回答

0

我相信你已經使用location.reload()方法實現刷新,而是嘗試使用如下所示的location.href重定向到同一頁面。

location.href = 「http://example.com/index.html#introduction

這將刷新頁面,還保持在#URL。

0

正如評論,如果你只使用靜態代碼,那麼你需要使用cookie(如果還支持舊版瀏覽器),否則你可以使用localstorage(用於現代瀏覽器)來存儲hashValue。

重裝不散列值調用上面的代碼ü需要保存散列值之前,使用下面的代碼

window.location.href = window.location.href.split("#")[0]; 

var hash = location.hash.substr(1); 
localStorage["hashValue"] = hash; 

retrive上述值以後作爲

var hash = localStorage["hashValue"]; 
0

嘗試

escape(window.location.href) 

如果要添加參數: 例如

escape(window.location.href="parameter="+param); 
0

試試這個

window.location.href = window.location