which way to reload a current page (using a button) would you prefer?
你更喜欢哪种方式重新加载当前页面(使用按钮)?
1 <input type="button" value="Reload" onClick="history.go(0)">
2 <input type="button" value="Reload" onClick="location.reload(true)">
3 <input type="button" value="Reload" onClick="window.location.reload(true)">
4 <input type="button" value="Reload" onClick="window.location.href=window.location.href">
5 <input type="button" value="Reload" onClick="document.location.reload(true)">
6 <input type="button" value="Reload" onClick="document.location.href=document.location.href">
As the URL of the page changes frequently AFAIK a 'fallback function' like
由于页面的URL频繁更改AFAIK的'后备功能'之类的
<a href="urlOfCurrentPage.html" onclick="window.location.reload(true);return false;">Reload</a>
won't work for me, right?
对我不起作用吧?
2 个解决方案
#1
55
Depends on what you want to do. The fourth and sixth methods there won't reload any form data, they essentially make a separate visit to the page. Some versions of Firefox also have issues with the third method. Other than that, I'd go with the fifth as a personal preference. It seems the clearest.
取决于你想做什么。第四种和第六种方法不会重新加载任何表单数据,它们实质上是单独访问页面。某些版本的Firefox也存在第三种方法的问题。除此之外,我会选择第五个作为个人偏好。这似乎是最清楚的。
#2
30
You may also do:
你也可以这样做:
wd
represents window || document:
wd代表窗口||文件:
- wd.location.assign(wd.location.href) : go to the URL
- wd.location.assign(wd.location.href):转到URL
- wd.location.replace(wd.location.href) : go to the URL and replace previous page in history
- wd.location.replace(wd.location.href):转到URL并替换历史记录中的上一页
- wd.location.reload(<true/false/blank>) : reload page from server/cache/cache
-
wd.location.reload(
):从服务器/缓存/缓存重新加载页面
#1
55
Depends on what you want to do. The fourth and sixth methods there won't reload any form data, they essentially make a separate visit to the page. Some versions of Firefox also have issues with the third method. Other than that, I'd go with the fifth as a personal preference. It seems the clearest.
取决于你想做什么。第四种和第六种方法不会重新加载任何表单数据,它们实质上是单独访问页面。某些版本的Firefox也存在第三种方法的问题。除此之外,我会选择第五个作为个人偏好。这似乎是最清楚的。
#2
30
You may also do:
你也可以这样做:
wd
represents window || document:
wd代表窗口||文件:
- wd.location.assign(wd.location.href) : go to the URL
- wd.location.assign(wd.location.href):转到URL
- wd.location.replace(wd.location.href) : go to the URL and replace previous page in history
- wd.location.replace(wd.location.href):转到URL并替换历史记录中的上一页
- wd.location.reload(<true/false/blank>) : reload page from server/cache/cache
-
wd.location.reload(
):从服务器/缓存/缓存重新加载页面