[javascript] Refreshing page on click of a button

I would like to refresh the current page when a button is clicked.

Using JavaScript, I have the following:

<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?

This question is related to javascript

The answer is


<button type="button" onClick="refreshPage()">Close</button>

<script>
function refreshPage(){
    window.location.reload();
} 
</script>

or

<button type="button" onClick="window.location.reload();">Close</button>

Works for every browser.

<button type="button" onClick="Refresh()">Close</button>

<script>
    function Refresh() {
        window.parent.location = window.parent.location.href;
    }
</script>

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">

<button onclick=location=URL>Refresh</button>

Small hack.


I'd suggest <a href='page1.jsp'>Refresh</a>.


This question actually is not JSP related, it is HTTP related. you can just do:

window.location = window.location;