I try to steer clear of modifying a page without the user triggering the change, much less automatically refresh or redirect a page. There are times when automatically refreshing the page is important, like when you pull up game play-by-play pages on NFL.com or ESPN.com. Whatever your reason for automatically refreshing the page, keep one thing in mind: auto-refresh only pages that have little interaction -- nothing more than a click.
我尝试避免在用户不触发更改的情况下修改页面,更不用说自动刷新或重定向页面了。 有时候,自动刷新页面很重要,例如在NFL.com或ESPN.com上拉逐个游戏页面时。 无论您是出于何种原因自动刷新页面,请记住一件事:仅自动刷新交互很少的页面-只需单击即可。
JavaScript方法 (The JavaScript Method)
var timer = null;
function auto_reload()
{
window.location = 'http://domain.com/page.php';
}
META标签方法 (The META Tag Method)
The following refreshes the page every 30 seconds.
以下内容每30秒刷新一次页面。
<head>
<meta http-equiv="refresh" content="30" />
</head>
翻译自: https://davidwalsh.name/automatically-refresh-page-javascript-meta-tags