Window. onload = f; and window. onload = f (); differences between IE and Firefox

Source: Internet
Author: User

Here, the result is assigned to him. The above is executed on IE, And the execution on Firefox is the correct result, that is, 1 --> -- 2> loading the body. The output result is what we want,

But IE is the above result 1 -- load the body, 2 is not displayed, the result is still null, It is speechless. In addition, an error is reported during debugging.Window. onload = f; this sentence has not been implemented yet. Alert ('2') is not executed because of a problem. Window. onload is of the object type by default and its value is null. Window. onload IE treats him as the object type, but Firefox treats him as an undefined type and is a keyword in IE. A type not defined in a browser is equivalent to a global variable. It turned out to be the difference between IE and Firefox.

1. Firefox does not support function names for adding events to objects. For example, the following code can be normally displayed in IE, but not in Firefox;
Function. Window. onload (){
Alert ("onLoad ");
}

To use:
Window. onload = fnshow;
Function fnshow (){
Alert ("onLoad ");
}

Or directly write as follows:
Window. onload = function (){
Alert ("onLoad ");
}
//-------

 

, Here window. onload is a function that is executed only when page loading is complete. The result should be: 2 --.> this is my XHTML page --> 1, window. onload is a function type.

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.