Hiermenus Go Forth, XX - DHTML Lab | 8
Hiermenus Go Forth, XX:
Version 4.0.13 - The Complete Script (Full-Window)
Incorrect Array Syntax
Many have written to complain about the following error message in IE:
What has baffled the writers even more is that the Netscape browsers (4 and 6) did not generate an error on the same page.
The cause of the error is incorrect menu array syntax. An extra trailing comma has been inserted into the array:
Here is a correctly formulated menu array:
HM_Array1 = [ [120,"mouse_x_position+15",,"black", "white","white","black","black","gray"], ["Experts","http://www.webref.com/experts/",1,0,1], ["Contents","http://www.webref.com/index2.html",1,0,0], ["Services","http://www.webref.com/index2.html",1,0,1], ["About","http://www.webref.com/about.html",1,0,0] ]
And here is an incorrect one:
HM_Array1 = [ [120,"mouse_x_position+15",,"black", "white","white","black","black","gray"], ["Experts","http://www.webref.com/experts/",1,0,1], ["Contents","http://www.webref.com/index2.html",1,0,0], ["Services","http://www.webref.com/index2.html",1,0,1], ["About","http://www.webref.com/about.html",1,0,0], ]
In Netscape, a final trailing comma in an literal array declaration is dropped!
In Explorer, a final trailing comma in an literal array declaration is regarded as a bona fide element with a null value!
For example, the following array:
myArray = ["one","two",,"four",];
has different length values for the two browser types:
Netscape: myArray.length: 4
Explorer: myArray.length: 5
Explorer, therefore, thinks there is one more item element than intended and attempts to build an additional menu item without the requisite item parameters. Instead of an item array, it finds a null value and cannot parse it, ergo the error.
Notice that in both browsers the third blank element is considered a valid null element. It is only the final blank element that affects the browsers differently.
I suppose there are arguments for both sides:
A trailing comma is illegal when using the
new Array()constructor, so it should be illegal in an array literal. Instead of throwing an error, it should be ignored.
In an array literal, null elements can be specified by simple comma addition. Therefore a final comma-induced null element is valid.
Whichever argument is more convincing, it doesn't change the fact that the comma should not be there. Since many authors make the trailing comma mistake, usually by cutting and pasting item element arrays, we have decided to have the HM script check for the mistake and to adjust the array, avoiding the error.
The HM script cannot check for all syntax errors. Version 4 has several checks but these always slow down the script. We want to include only the most important checks. Please review your syntax carefully.
On the next page, our second fix.
Produced by Peter Belesis andAll Rights Reserved. Legal Notices.
Created: July 12, 2001
Revised: July 12, 2001