How to Reload a Page with Javascript

258

A simple page reload with javascript can be very useful. Here is the code:

<script type="text/javascript">
window.location.reload();
</script>

That will keep refreshing the page you are on. To trigger the reload event you can use the code inline on a HTML element

<a href="javascript:void(0)" onclick="window.location.reload();">Reload the Page</a>

To abstract the code out and use it more than once, in your HTML head create

<script type="text/javascript">
function pageReload(){
       window.location.reload();
}
</script>

And create an HTML element like so

<a href="javascript:void(0)" onclick="pageReload();">Reload the Page</a>


0 comments ↓

If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment