When does a body onLoad gets called?

前端 未结 4 1031
旧巷少年郎
旧巷少年郎 2020-12-19 07:29

I need to understand when does a body\'s onload gets called

I read in w3school that onload=Script to be run when a document load what does

相关标签:
4条回答
  • 2020-12-19 08:27

    Unlike w3schools, MDN explains when the event is fired:

    The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.

    So the DOM tree is ready and all elements have been loaded.

    0 讨论(0)
  • 2020-12-19 08:27

    The onLoad event is fired after the successful completion of the dom tree, e.g. the successful loading of all the elements inside the body.

    0 讨论(0)
  • 2020-12-19 08:29

    The onload event is triggered when the DOM tree is ready. This means that all elements on your page are available to the script. Document.onload may be triggered before the page is rendered or images are loaded.

    0 讨论(0)
  • 2020-12-19 08:30

    Onload executes when DOM fully loaded.This means it is executed after end of your page. This is useful when you want to do some task when document is fully loaed.

    You can do this in many ways but few ways is here

    <body onload="YOUR ACTION">
    

    is similar to

    <script type="text/javascript>
    window.onload=function(){
       //YOUR ACTION  
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题