[英]How do I auto refresh HTML page every hour?
I want to refresh an HTML page every hour automatically in the background. 我想每小时自动在后台刷新HTML页面。 I was thinking about using PHP but I'm not sure what if that's possible. 我当时正在考虑使用PHP,但不确定是否可行。
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). 如果这在PHP和cron工作中是可行的,请告诉我(最好使用代码)。 Thank you. 谢谢。
You can use javascript setInterval(); 您可以使用javascript setInterval();
<script>
$(document).ready(function(){
setInterval(function(){ reload_page(); },60*60000);
});
function reload_page()
{
window.location.reload(true);
}
</script>
Try this : 尝试这个 :
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "3600";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
Refer to this answer https://stackoverflow.com/a/19807718/6390490 请参阅此答案https://stackoverflow.com/a/19807718/6390490
Refresh document every 300 seconds using HTML Meta tag 使用HTML Meta标签每300秒刷新一次文档
EDIT: for background you have to use ajax something like this https://stackoverflow.com/a/25446696/6390490 编辑:对于背景,您必须使用像这样的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);
for server side refreshing use 供服务器端刷新使用
header("Refresh: 300;url='http://thepage.com/example'");//set time here as per your need
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.