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 ?
No, there isn't a way to delay the window onload. You could try to add a lot of images and other things that take a long time to load, but that's not an ideal solution. Instead, you can use setTimeout to make code run after a period of time. setTimeout(function(){ window.
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images. This is in contrast to DOMContentLoaded , which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading.
The onload attribute fires when an object has been loaded. onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).
ready() is a jQuery event which occurs when the HTML document has been fully loaded, while the window. onload event occurs later, when everything including images on the page loaded. Also window. onload is a pure javascript event in the DOM, while the $(document). ready() event is a method in jQuery.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With