Ron
Ron

Reputation: 105

How do I auto refresh HTML page every hour?

I want to refresh an HTML page every hour automatically in the background. I was thinking about using PHP but I'm not sure what if that's possible.

This is all the I have:

<meta http-equiv="refresh" content="3600" >

But this doesn't refresh automatically in the background. How can I do this? If this is possible in PHP and a cron job please let me know (with code preferably). Thank you.

Upvotes: 1

Views: 20692

Answers (4)

Jalle
Jalle

Reputation: 1

setTimeout(function reloadData() {
  location.reload();
},60000*60);

Upvotes: 0

smarttechy
smarttechy

Reputation: 902

Refer to this answer https://stackoverflow.com/a/19807718/6390490

Refresh document every 300 seconds using HTML Meta tag

EDIT: for background you have to use ajax something like this https://stackoverflow.com/a/25446696/6390490

function loadlink(){
   $('#links').load('test.php',function () {
     $(this).unwrap();
});
}

 loadlink(); // This will run on page load
 setInterval(function(){
 loadlink() // this will run after every 5 seconds
}, 5000);

for server side refreshing use

 header("Refresh: 300;url='http://thepage.com/example'");//set time here as per your need

Upvotes: 0

Dhara Parmar
Dhara Parmar

Reputation: 8101

You can use javascript setInterval();

<script>
 $(document).ready(function(){
    setInterval(function(){ reload_page(); },60*60000);
 });

 function reload_page()
 {
    window.location.reload(true);
 }
</script>

Upvotes: 5

chandresh_cool
chandresh_cool

Reputation: 11830

Try this :

<?php
    $page = $_SERVER['PHP_SELF'];
     $sec = "3600";
?>
<html>
    <head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">

Upvotes: 1

Related Questions