问题
How can I refresh or reload a page with timeout in javascript or jquery only when
- a specific class is visible or
- img is not found
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.
回答1:
Use the setTimeout() global method to create a timer. This will reload the page after 5000 milliseconds (5 seconds):
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>
来源:https://stackoverflow.com/questions/42013358/how-to-refresh-or-reload-a-page-with-timeout-in-javascript-or-jquery