admin管理员组

文章数量:1301478

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?

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?

Share Improve this question asked Sep 24, 2015 at 6:57 ImadImad 7,49014 gold badges62 silver badges122 bronze badges 1
  • Possible duplicate of How to delay calling of javascript function? – Vadzim Commented Nov 1, 2017 at 1:15
Add a comment  | 

3 Answers 3

Reset to default 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);
}

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

setTimeout(myFunc, 3000);

Using setTimeout:

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

with lambda..

本文标签: javascriptExecute JS function after some time of page loadStack Overflow