javascriptjqueryyui

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


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 ?


Solution

  • 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.