【发布时间】:2014-08-15 13:18:37
【问题描述】:
这是我的问题:我需要显示一段时间的消息,然后重新加载页面。 有人可以告诉我如何在一定的延迟后重新加载页面吗?
【问题讨论】:
标签: javascript jquery html
这是我的问题:我需要显示一段时间的消息,然后重新加载页面。 有人可以告诉我如何在一定的延迟后重新加载页面吗?
【问题讨论】:
标签: javascript jquery html
你甚至不需要 jQuery 或 HTML5:
setTimeout(location.reload.bind(location), 60000);
这将等待 1 分钟(60,000 毫秒),然后调用 location.reload 函数,这是刷新页面的内置函数。
【讨论】:
setTimeout(function(){
window.location.reload(); // you can pass true to reload function to ignore the client cache and reload from the server
},delayTime); //delayTime should be written in milliseconds e.g. 1000 which equals 1 second
更新:
使用 ES6 的单行代码:
setTimeout(() => window.location.reload(), delayTime);
【讨论】:
你可以试试这个不用js,它会循环:
<meta http-equiv="refresh" content="5"/> <!-- 5 sec interval-->
<h1>Page refersh in every 5 seconds...</h1>
您甚至可以导航到不同的页面,访问 google 主页
<meta http-equiv="refresh" content="5;http://www.google.com"/> <!-- 5 sec delay-->
<h1>Redirecting in 5 seconds...</h1>
【讨论】:
window.setTimeout。