Multiple methods to execute a js function after the jsp page is fully loaded

Source: Internet
Author: User

Method 1:Run the openTheIndexPage () method after the page is fully loaded as follows:
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Telecommunications Data Collection System </title>
<Script type = "text/javascript" src = "<% = contextPath %>/js/baseframe. js"> </script>
<Script type = "text/javascript" src = "<% = contextPath %>/js/cookies. js"> </script>
<Script type = "text/javascript" src = "<% = contextPath %>/js/tag. js"> </script>
<Script language = "javascript" for = "window" event = "onload">
Function openTheIndexPage (){
OpenMyURIWithCid (true, 'root', 'idx', "iframe/dispatch. jsp? Url = tdc/zhk/impctrlobjinf/index. jsp ", 'homepage ',
'Top. tagmenu ', 'top. maintop', true,
'System/accessPaths. do? CurrentModuleCode = idx ',
'Mainmenu ', true );
};
If (document. readyState = "complete "){
OpenTheIndexPage ();
}
</Script>
</Head>
<Body>
</Body>
</Html>

Method 2: It can be the following, but the effect is not as good as method 1.
Copy codeThe Code is as follows:
<Body onload = "function name ()"> </body>
<Script> window. onload = function name </script>
<Script language = "javascript" for = "window" event = "onload"> function name (); </script>

In the second method, only one function can be written, and no variable can be given. It is best to use the last function, which can be written independently.

Method 3: <Body onload = "xxx ()"> </body> xxx () indicates the function you want to execute.

Method 4: Add defer to the script tag
That is, <script defer = "defer" language = "javascript">
Or <script defer language = "javascript">
Run the script after the whole page is loaded. (No effect)

Related Article

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.