How to execute JS after the page is fully loaded

Source: Internet
Author: User

Use scriptin theDeferproperty.
Scriptin thedeferproperty by default isfalsethe.
In other words: If you are writing a script, adddeferproperty, the browser does not have to deal with it immediately when it downloads the script, but continues to download and parse the page, which improves the performance of the download.
There are many kinds of situations like this. Like you've defined a lot.JavaScriptvariable, or in a reference file (. Incwrite a lot of scripts that need to be processed, so you might want to include them in these scripts .deferproperties, it is certainly helpful to improve performance.
Examples are as follows:
<script language= "JavaScript" defer>
var object = new Object ();
....
</script>
Becausedeferproperty is default tofalse, then here<script language= "javascript" defer>Explicit Declarationdeferproperty is equivalent to<script language= "javascript" defer=true>
Declared thedeferproperty, you need to determine if there are other variables referencing thedefera variable in the script block, otherwise it will cause a script error to occur

Combining <body onload= "xx ()" >

And

<script defer= "Defer" >

XX ();

</script>

The JS will be executed after the page is loaded, including the IFRAME loading

How to execute JS after the page is fully loaded

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.