7

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?

1

3 Answers 3

11

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);
}

0
9

Use setTimeout instead, as it is called only once after the pause:

setTimeout(myFunc, 3000);
0
3

Using setTimeout:

 setTimeout(function(){myfunc()}, 3000);

with lambda..

2
  • Thanks, appriciate your help :)
    – Imad
    Sep 24, 2015 at 7:14
  • appreciation is appreciated :)
    – maioman
    Sep 24, 2015 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.