Is it allowed to use <body onLoad="myfunc()">
along with jQuery's document.ready()
handlers? I can't find a way to achieve the same functionality of the <body onLoad>
with jQuery.
An example of a use case would be a facebook application. An Iframe facebook app requires the use of the FB.Canvas.setSize
function which resize the iframe.
I would need to fire it up only when all elements on the page are finished loading.
The onload event occurs 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.).
The main differences between the two are: Body. Onload() event will be called only after the DOM and associated resources like images got loaded, but jQuery's document. ready() event will be called once the DOM is loaded i.e., it wont wait for the resources like images to get loaded.
The body. onload() event will be called once the DOM and all associated resources like images got loaded. Basically, onload() will be called when the page has been fully loaded with entire images, iframes and stylesheets, etc.
ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.
$(window).load(myfunc)
is what you're looking for. If you're working with the load event of an iframe, you can replace window
with the iframe element/selector.
This works as well:
$(window).load(function(){ // .. myfunc(); // .. });
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