How to delay the onLoad event which gets fired on the browser?

kay am see picture kay am see · Oct 17, 2011 · Viewed 17.1k times · Source

I am trying to delay the onLoad event that gets fired. Is there a way to delay this event strictly using javascript on the client side ?

Answer

Mic picture Mic · Oct 17, 2011

If you put a script tag at the end of the body like:

<body>

  ...

  <script>
    setTimeout(function(){
      //deferred onload
    }, 2000);
  </script>
</body>

The function will be executed after 2 sec in this case

As said in my comment below: you shouldn't rely on a delay. But use a callback on a certain event. If impossible, may be a better bad solution, is to use setInterval with a function that check every X msec if the thing you are waiting for is present, and fire.