Josh
Josh

Reputation: 121

How to reload a page using javascript after the whole page is loaded

I want to reload a page after the whole PHP script is loaded, and printed the result. Yeah, i want an infinite loop

This is the script

setTimeout(function(){
   window.location.reload(1);
}, 5000);

Upvotes: 1

Views: 43

Answers (1)

Mohammad Hamedani
Mohammad Hamedani

Reputation: 3354

You can use window.location.reload function to load page. If you need to reload after page completed, use window.onload event. (reload function has one parameter that can disable cache.)

window.onload = function(){ window.location.reload()} //reload with using browser cache
window.onload = function(){ window.location.reload(true)} //reload without using browser cache

Another way is sending refresh header to browser by set refresh header in php:

<?php
header("refresh:5"); //loaded page reload after 5 seconds 
?>

Upvotes: 2

Related Questions