[英]How to refresh or reload a page with timeout in javascript or jquery
How can I refresh or reload a page with timeout in javascript or jquery only when 仅在以下情况下,如何才能在javascript或jquery中刷新或重新加载带有超时的页面:
i found this https://stackoverflow.com/a/14787543/7051635 but there is no timeout and when i'm in front of an omg not found, nothing happened. 我发现了这个https://stackoverflow.com/a/14787543/7051635,但是没有超时,当我在一个未找到的omg面前时,什么也没发生。
Use the setTimeout()
global method to create a timer. 使用setTimeout()
全局方法创建计时器。 This will reload the page after 5000 milliseconds (5 seconds): 这将在5000毫秒(5秒)后重新加载页面:
setTimeout(function(){ location.reload(); }, 5000);
This code can be added to any event you need it to. 可以将此代码添加到您需要的任何事件中。 So, for example: 因此,例如:
var theDiv = document.querySelector("div"); // When the div is clicked, wait 5 seconds and then hide it. theDiv.addEventListener("click", function(){ setTimeout(function(){ theDiv.classList.add("hide"); }, 5000); });
.hide { display:none; }
<div>Now you see me.</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.