Html/js OnLoad's explanation

Source: Internet
Author: User

Wait for the page to finish loading before executing

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Document</title>
<script type= "Text/javascript" >

Window.onload=function () {
Alert (Exist ("Getspantext"));
Alert (exist ("111"))
// }

function LoadText () {
var spanvalue = document.getElementById ("Getspantext"). InnerHTML;
Alert ("Spanvalue =" + Spanvalue);
Alert (Exist ("Getspantext"));
}
function exist (ID) {
var S=document.getelementbyid (ID);
if (s) {
return True
}
else{
return False
}
}

</script>
<body onload= "LoadText ()" >
<span id= "Getspantext" >jason</span "
</body>

Executes a piece of JavaScript immediately after the page is loaded:

onload="load()">

Try it yourself.

Browser support
IE Firefox Chrome Safari Opera

The OnLoad property is supported by all major browsers.

Definition and usage

The OnLoad property is triggered when an object is loaded.

OnLoad is commonly used in <body>, and once all content is fully loaded (including images, script files, CSS files, etc.), a script is executed.

The difference between HTML 4.01 and HTML5

No.

Grammar
<element onload= "script" >
Property value
value Description
Script The script that runs when onload occurs.

JS OnLoad Event

Event Object

Definition and usage

The OnLoad event occurs immediately after the page or image has finished loading.

Grammar
Onload= "Somejavascriptcode"
Parameters Description
Somejavascriptcode Necessary. Specifies the JavaScript that is executed when the event occurs.
HTML tags that support the event:
<body>, <frame>, <frameset>, <iframe>, , <link>, <script>
JavaScript objects that support the event:
Image, layer, window
Instance

In this example, the text "page is loaded" will be displayed in the status bar:

onload="load()"></body>
Tiy
OnLoad
How to use onload to display a piece of text in the status bar when the page finishes loading.

Event Object

Html/js OnLoad's explanation

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.