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