Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • document.ready() v/s window.onload()

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 182
    Comment on it

    document.ready() v/s window.onload():

        Most of us think that document.ready and window.onload is one of the same thing the only difference is that window.onload is used in javascript while we use document.ready in Jquery.

    But this is not correct they are different, Let us see how:-

        In window.onload the load event fires only after all the content such as content, asynchronous javascript, frames and images is loaded.

    Whereas

        In document.ready event is fired once all the html tags/scripts are loaded, it does not wait for the frames & images. So we can say that it is fired a bit earlier than window.onload.

    Other Scenarios:

        Sometimes we are having very large images on the page, so if we are using window.onload then it will slow down the execution, but as document.ready does not wait for the whole content to get loaded therefore it will not slow down the execution.

        Also incase of update panel in asp.net (provides partial postback) if we are using document.ready then we have to be careful as document.ready will be executed only once it will not be called in every postback, but if we are using window.onload then it will be called on every partial postback.

        Now as the difference is clear therefore we can say that we shall use document.ready when we have to execute script once the content is loaded (i.e DOM), but should use window.onload if we have to perform some action on the content such as images etc.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: