2013-04-10 173 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