Are you looking how to refresh page in javascript ? Here we have provided a complete information on javascript window refresh page script. So, go through the entire article to get a clear view on how to refresh page in javascript?

If you have a basic idea on javascript, the immediate solution for javascript refresh page would be adding a ‘true’ keyword using document.location.reload(). This helps to reload javascript page from the server instead of cache. As an alternate, you can use the ‘false’ keyword to reload or refresh page in javascript.

If you are still wondering how to refresh page in javascript either in auto or manual mode, then do check the javascript refresh code provided below.

How to Refresh Page in Javascript? – Auto Run Script

If you want to refresh page in javascript automatically, run the script given below:

<input type=”button” value=”Reload Page” onClick=”document.location.reload(true)”>

<p>Clicking the above button will refresh the page/frame.</p>

<img src=”/pix/samples/4s.jpg” alt=”Sample image”>

Javascript Reload Page – Auto Refresh With Time Delay

<html>

<head>

<title>Example</title>

<script>

<!–

function timedRefresh(timeoutPeriod) {

            setTimeout(“location.reload(true);”,timeoutPeriod);

}

window.onload = timedRefresh(5000);

//   –>

</script>

</head>

<body>

<p>This page will refresh every 5 seconds. This is because we’re using the ‘onload’ event to call our function. We are passing in the value ‘5000’, which equals 5 seconds.</p>

<img src=”/pix/samples/4s.jpg” alt=”Sample image”>

<p>But hey, try not to annoy your users too much with unnecessary page refreshes every few seconds!</p>

</body>

</html>

Other Javascript Loading Scripts

<script>

<!–

function timedRefresh(timeoutPeriod) {

            setTimeout(“location.reload(true);”,timeoutPeriod);

}

//   –>

</script>

<p><a href=”javascript:timedRefresh(2000)”>Refresh this page in 2 seconds</a></p>

<p><a href=”javascript:timedRefresh(5000)”>Refresh this page in 5 seconds</a></p>

<img src=”/pix/samples/4s.jpg” alt=”Sample image”>

We hope now you understand how to refresh page in javascript? If you still have any queries related to reload page javascript contact us using the comment section below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here