DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum VII (v3.07) | 3
Hierarchical Menus Ver. 3 - Addendum VII (v3.07)
two minor fixes for both browsers
The javascript: URL Problem
In Version 2.1 of the menu script, we introduced the use of javascript: URLs in the menu arrays. This improvement allowed us to link the menu items to script functions, as well as enabling us to load linked-to pages in different frames or a new window.
This modification was achieved by altering the linkIt() function to read:
function linkIt() { if (this.linkText.indexOf("javascript")!=-1) eval(this.linkText) // we added this line else menuLoc.location.href = this.linkText; }
linkIt() now checked for the existence of the word "javascript" in the linkText property, assigned from the URL array element. If it was found, linkIt() assumed that a javascript: URL was called for, so it evaluated the property, executing the expected JavaScript statement.
This works fine if the relevant array included the word "javascript" in this context:
... "My Link Text","javascript:open('newwindowpage.html')",0, ...
But, what about this context:
... "My Link Text","https://www.mydomain.com/pages/javascript/pagewithscript.html",0, ...
Here "javascript" is simply a non-dynamic word used as part of the regular http: path. Our script, unfortunately, thinks the valid URL is a javascript statement and attempts to execute it.
Since a javascript: URL needs a colon, we should look out for the colon as well. The linkIt() function should therefore read:
function linkIt() { if (this.linkText.indexOf("javascript:")!=-1) eval(this.linkText) else menuLoc.location.href = this.linkText; }
The two links below display a one-item menu with "javascript" in the path, created from this array. Mouse over the links and click the item to see the difference in behavior between previous versions and 3.07. The left menu will generate an error, of course.
arMenu1 = new Array( 120, "","", "","", "","", "","", "Page in the 'javascript' subdirectory","javascript/page.html",0 )
Behavior with hierMenus2.1-3.06 | Behaviour with hierMenus3.07 |
show menu | show menu |
Our second problem was not as easy to trace.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.Created: July 27, 1999
Revised: July 27, 1999
URL: https://www.webreference.com/dhtml/column21/addendum7/col21addVII2.html