Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button that refreshes the page on click

People also ask

How do you refresh a page when a button is clicked?

reload() method gives the same result as pressing the reload button on your browser. This method reloads the page from directly the browser's cache by default.

What buttons refresh the page?

In virtually all browsers, pressing the F5 key will cause the current page to refresh (on some Windows computers, you may have to hold down Fn while pressing F5 ). If you can't find the F5 key, there are other operating system-specific shortcuts you can use: Windows — Hold down Ctrl and press R .

How do I trigger a refresh page?

reload() method reloads the current web page. The method gives the exact same result as pressing the RELOAD button in your browser. The JavaScript reload page method loads the page from the cache by default. If the forceGet property is set to true, the page is reloaded from the server.

How do I refresh my screen with buttons?

Pressing the F5 function key can act as a keyboard shortcut to refresh the Windows desktop screen.


Use onClick with window.location.reload(), i.e. :

<button onClick="window.location.reload();">Refresh Page</button>

Or history.go(0), i.e.:

<button onClick="history.go(0);">Refresh Page</button>

Or window.location.href=window.location.href for 'full' reload, i.e.:

<button onClick="window.location.href=window.location.href">Refresh Page</button>

The Button element - developer.mozilla.org


This works for me:

function refreshPage(){
    window.location.reload();
} 
<button type="submit" onClick="refreshPage()">Refresh Button</button>

<a onClick="window.location.reload()">Refresh</a>

This really works perfect for me.


Only this realy reloads page (Today)

<input type="button" value="Refresh Page" onClick="location.href=location.href">

Others do not exactly reload. They keep values inside text boxes.


I noticed that all the answers here use inline onClick handlers. It's generally recommended to keep HTML and Javascript separate.

Here's an answer that adds a click event listener directly to the button. When it's clicked, it calls location.reload which causes the page to reload with the current URL.

const refreshButton = document.querySelector('.refresh-button');

const refreshPage = () => {
  location.reload();
}

refreshButton.addEventListener('click', refreshPage)
.demo-image {
  display: block;
}
<button class="refresh-button">Refresh!</button>
<img class="demo-image" src="https://picsum.photos/200/300">