var interval = setInterval(function(){alert("I am alive.")},delay)
I want to register my setInterval explicitly as I want to run the interval after every delay time even if the page in which I have written it is destroyed. Which actually works fine if my delay is 5 minutes and I wait till the setInterval is registered for the first time then even if I change the page I get the alerts. But if I change the page before delay time then I dont get alert as it is never registered at all. So is there any way where I can directly register setInterval as soon as I load the page.
Have you tried putting it a document ready? So when the page loads itll run straight away;
var interval;
$(document).ready(function) {
interval = setInterval(function(){alert("I am alive.")},delay);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.