ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Menu U. A quick guide to easy, CSS-based pop-up menus
JAVASCRIPT --- 08/27/2002

David Wall

The idea behind the Menu component is simple, and very much in line with the ideals of object orientation. You simply make reference to a canned JavaScript (.js) file from a one-line <SCRIPT> tag in the HEAD section of your page then, later, call on it when you want to create your menu object. When creating that object, you define menu entries (specifically, the strings that represent menu options) as members. Then, you call a function -- also defined in the imported library file -- when you want the menu to pop up in the user's browser window. 

On this topic

So, to establish a connection to the library (which you can download from the link at the end of this article, and use free of charge), you make a quick call from a SCRIPT element, like this:

<SCRIPT LANGUAGE="JavaScript1.2" SRC="menu.js"></SCRIPT>

That assumes that menu.js is stored in the same directory on the Web server as the document in which the line above appears. Having done that, you can build your menu object (entries, followed by the links they call) and use the writeMenus() method to record the menu object in the CSS stylesheet that defines its appearance on the page (the library handles the details out of sight; don't worry about the CSS stuff too much):

<SCRIPT LANGUAGE="JavaScript1.2">
var popupMenu = new Menu(); popupMenu.addMenuItem("News", "location='http://www.drudgereport.com'"); popupMenu.addMenuItem("Tech", "location='http://www.itworld.com'"); popupMenu.addMenuItem("Miscellaneous", "location='http://www.davidwall.com'"); myMenu2.writeMenus(); </SCRIPT>

Then, when you want to display the menu you've defined, invoke the showMenu() method. Usually, you'll call that method in response to a click on a graphic that represents the "menu bar" entry for the menu, or perhaps a mouseOver event on some kind of outline entry.

This article contains more detailed information about the library, and includes a download link: http://developer.netscape.com/viewsource/smith_menu/smith_menu.html

Also, if you haven't checked out Mozilla 1.0 yet, have a look: http://www.mozilla.org/releases/stable.html_

 

David Wall works as a freelance writer, programmer, lecturer, and consultant. Based near Washington, D.C., David has written and co- written several books, including Graphics Programming with JFC. David can be reached at David.Wall@itworld.com.



Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
KODAK i1400 Series Scanners stand up to the challenge
Top 5 Reasons to Combine App Performance and Security
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Newsletters  JAVASCRIPT
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   Industry Standard   Infoworld   ITworld  
JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

DEMO   IDG Connect   IDG Knowledge Hub   IDG TechNetwork   IDG World Expo  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.