最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if 5 minutes passed after script load - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 7

Simply 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
发布评论

评论列表(0)

  1. 暂无评论