繁体   English   中英

如何每小时自动刷新HTML页面?

[英]How do I auto refresh HTML page every hour?

我想每小时自动在后台刷新HTML页面。 我当时正在考虑使用PHP,但不确定是否可行。

这就是我所拥有的:

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

但这不会在后台自动刷新。 我怎样才能做到这一点? 如果这在PHP和cron工作中是可行的,请告诉我(最好使用代码)。 谢谢。

您可以使用javascript setInterval();

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

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

尝试这个 :

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

请参阅此答案https://stackoverflow.com/a/19807718/6390490

使用HTML Meta标签每300秒刷新一次文档

编辑:对于背景,您必须使用像这样的Ajax 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);

供服务器端刷新使用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM