Javascript 单击按钮刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5480945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refreshing page on click of a button
提问by curiousgeorge
I would like to refresh the current page when a button is clicked.
我想在单击按钮时刷新当前页面。
Using JavaScript, I have the following:
使用 JavaScript,我有以下内容:
<button type="button" onClick="refreshPage()">Close</button>
<script>
function refreshPage() {
// What do I put here?
}
</script>
What would to code look like to refresh the current page?
刷新当前页面的代码是什么样的?
回答by amit_g
<button type="button" onClick="refreshPage()">Close</button>
<script>
function refreshPage(){
window.location.reload();
}
</script>
or
或者
<button type="button" onClick="window.location.reload();">Close</button>
回答by Rolwin Crasta
There are several ways to reload the current page using a button or other trigger. The examples below use a button click to reload the page but you can use a text hyperlink or any trigger you like.
有几种方法可以使用按钮或其他触发器重新加载当前页面。下面的示例使用按钮单击来重新加载页面,但您可以使用文本超链接或任何您喜欢的触发器。
<input type="button" value="Reload Page" onClick="window.location.reload()">
<input type="button" value="Reload Page" onClick="history.go(0)">
<input type="button" value="Reload Page" onClick="window.location.href=window.location.href">
回答by MustafaP
Works for every browser.
适用于所有浏览器。
<button type="button" onClick="Refresh()">Close</button>
<script>
function Refresh() {
window.parent.location = window.parent.location.href;
}
</script>
回答by James.Xu
This question actually is not JSP related, it is HTTP related. you can just do:
这个问题实际上与JSP无关,与HTTP有关。你可以这样做:
window.location = window.location;
window.location = window.location;
回答by adatapost
I'd suggest <a href='page1.jsp'>Refresh</a>
.
我建议<a href='page1.jsp'>Refresh</a>
。
回答by Thielicious
<button onclick=location=URL>Refresh</button>
Small hack.
小黑客。