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?
To do not refresh the page we add event. preventDefault(); at the end of our JavaScript function.
You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.
Pressing the F5 function key can act as a keyboard shortcut to refresh the Windows desktop screen.
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.
<button type="button" onClick="refreshPage()">Close</button> <script> function refreshPage(){ window.location.reload(); } </script>
or
<button type="button" onClick="window.location.reload();">Close</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With