Article Introduction: JavaScript compatibility has long been a major problem for Web developers. The differences between formal norms, factual standards and various implementations make many developers suffer day and night. To this end, mainly from the following aspects of the differences to summarize IE and Firefox javascript compatibility. |
1. getyear () method
"Analysis Notes" first look at the following code:
var year= new Date (). getyear ();
document.write (year);
In IE, the date is "2010", in Firefox, see the date is "110", mainly because in Firefox inside GetYear return is "Current year-1900" value.
"Compatibility Handling"
Plus the judgment of the year, such as:
var year= new Date (). getyear ();
Year = (year<1900? ( 1900+year): Year); document.write (year);
It can also be invoked via getFullYear getUTCFullYear:
var year = new Date (). getFullYear ();
document.write (year);
2. Eval () function
"Analysis Notes" in IE, you can use either eval ("Idname") or getElementById ("Idname") to get an HTML object with an ID of Idname; Firefox can only use getElementById ("Idname") To get the HTML object with the ID idname.
"Compatible processing" unifies getElementById ("Idname") to obtain an HTML object with an ID of idname.
3. Const statement
The Const keyword cannot be used in IE by the analysis note. Such as:
Const CONSTVAR = 32;
This is a syntax error in IE.
"Compatibility handling" does not use const and is substituted with var.
4. var
For an explanation of the analysis, see the following code:
Echo=function (str) {
document.write (str);
}
This function in IE on the normal operation, Firefox under the error.
"Compatible processing" and adding Var before echo is normal, and this is what we refer to as the purpose of Var.
5. The question of the const
The Const keyword cannot be used in IE by the analysis note. such as const CONSTVAR = 32; This is a syntax error in IE.
"Workaround" does not use const and is substituted with var.