admin管理员组文章数量:1356941
Basically I need quite (probably) a simple thing check if 5 minutes passed after script load.
Script structure should be like this:
var check;
check = 300; //5 minutes
if ( count to 300 seconds >= check) {
//do magic
} else {
}
Basically I need quite (probably) a simple thing check if 5 minutes passed after script load.
Script structure should be like this:
var check;
check = 300; //5 minutes
if ( count to 300 seconds >= check) {
//do magic
} else {
}
Share
Improve this question
asked Feb 22, 2017 at 16:35
me01me01
411 silver badge2 bronze badges
1
-
You probably want
setTimeout
, you just don't know it yet. Anyway, see How to get the hours difference between two date objects? – Theraot Commented Feb 22, 2017 at 16:37
2 Answers
Reset to default 7Simply save the time when the load
event has been triggered and then check against it.
var loadTime;
window.onload = function() {
loadTime = (new Date().getTime()) / 1000; // convert milliseconds to seconds.
};
// your code
var currentTime = (new Date().getTime()) / 1000;
if (currentTime - loadTime >= 300) {
// then more than 5 minutes elapsed.
}
The easiest and simplest way could be this:
setTimeout(function(){
// do stuff
}, 300 * 1000); // time in milliseconds
本文标签: javascriptCheck if 5 minutes passed after script loadStack Overflow
版权声明:本文标题:javascript - Check if 5 minutes passed after script load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743953223a2567671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论