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

问题描述 投票:0回答:4
javascript php html
4个回答
5
投票

您可以使用javascript setInterval();

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

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

1
投票

试试这个:

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

0
投票

参考这个答案https://stackoverflow.com/a/19807718/6390490

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

编辑:对于背景,你必须使用像这样的ajaxhttps://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

0
投票
setTimeout(function reloadData() {
  location.reload();
},60000*60);
© www.soinside.com 2019 - 2024. All rights reserved.