Yet another IE woe – if you want your code to work on IE – be forewarned that harmless looking like the one below would break with “Object doesn’t support this action” error.
items=[];//define a array
length=items.length;//throws error since the term length is treated special in IE
for(item in items){
//again the term item is treated in a special way in IE – would throw the same error.
}
Either make sure these are local variables by prefixing them with var.
items=[];//define a array
var length=items.length;//throws error since the term length is treated special in IE
for(var item in items){
//again the term item is treated in a special – would throw the same error.
}
otherwise rename the variables
items=[];//define a array
mylength=items.length;//throws error since the term length is treated special in IE
for(myitem in items){
//again the term item is treated in a special – would throw the same error.
}
After a lot of digging, I found that any variable declared without the var keyword is considered to global in Javascript. Specifically in IE – They get attached to a global collection called document.all.
So helper methods associated with document.all such as
- item
- namedItem
- tags
- urns
and the property “length” are all considered reserved with respect to global variables in IE.
Also refrain from using these words as IDs for any HTML element.