The difference between onreadystatechange and onload in JS

Source: Internet
Author: User

The script element of IE only supports the onreadystatechange event, and the OnLoad event is not supported. The script element of FF does not support the onReadyStateChange event, only the OnLoad event is supported. If you want to perform an operation on a <script src= "xx.js" > Load, FF uses the OnLoad event, and IE combines onreadystatechange events and this.readystate,
Here is an example of IE: <script type= "Text/javascript" src= "xx.xx" onreadstatechange= "if (this.readystate== ' Load ') alert (' Loaded '); " The value of ></script>this.readystate ' loaded ' or ' complete ' can indicate that the script has been loaded. How to combine the differences between IE and FF? Refer to the source code for jquery: var script = document.createelement (' script '); script.src= "Xx.js"; script.onload = Script.onreadystatechange = function () {     if (  ! this.readystate     ///This is the judgment statement of FF, because there is no readyState this person value under FF, IE's readyState must have value          | | this.readystate== ' loaded ' | | this.readystate== ' complete '   //This is IE's judgment statement    ) {          Alert (' Loaded ');}    };

documentreturns "Loading" when the document is loading. Returns "Interactive" and raises an event when the document finishes rendering but when an inline resource is loaded DOMContentLoaded . When the document is loaded, return "complete" and raise the load event.

readystatechange事件Will be in documentOccurs when the property value of the ReadyState property on an object changes. Syntax
var string = document.readyState;
Example
//analog domcontentloadeddocume Nt.onreadystatechange = function  ({if  (Document.readystate == " interactive "{initapplication (}}        /span>              
//simulation Load event Document.onreadystatechange = function {if .readystate ==  "complete ") {initapplication }         
<iframe src="../../planmanage/planmanage/planBaseInfoAction.do?doType=212" width="98%" height="330" scrolling="no" frameborder="0" id="content51" name="content50" style="visibility: hidden;" onreadystatechange="stateChangeIE(this,‘loading50‘)" onload="stateChangeFirefox(this,‘loading50‘)"></iframe>   

The difference between onreadystatechange and onload in JS

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.