Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute JS function after some time of page load

I have javascript function and that should be called after 3 seconds of complete page load. I know about setIntervel but it repeat execution after certain time interval. I want it to execute once. Is it even possible?

like image 694
Imad Avatar asked Sep 24 '15 06:09

Imad


1 Answers

The onload event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading, After onload you can use setTimeout to delay your function execution..

var myFunc = function() {
  alert('After 3 seconds of page load!');
}
window.onload = function() {
  setTimeout(myFunc, 3000);
}
like image 109
Rayon Avatar answered Sep 20 '22 00:09

Rayon