Submit FAQs Awards Usage Terms Contact
Categories
Partners
DaniWeb is an exciting community for web developers, Internet marketers, and technology enthusiasts.
Other Sections
Advertisement

Compatibility
Bookmark online:

FF1+ IE5+

Context menu Script

Updated: August 22nd, 01'  Author: Dynamic Drive

Description: With IE 5 and now NS6.1+, you can add a context menu to your webpage. What's a context menu? Well, it's a custom menu that pops up in place of the default context menu when you right click your mouse. This custom menu can do virtually anything you want it to do, although in this script, it's designed to go to a set of URLs. Also note that window targeting is possible with each link, so the links can be specified to open either in current window, or another. See footnote for more info on this.

Demo: Right click anywhere inside this document if you're using IE 5 or NS6.1+. Try clicking on "What's New", and notice how the link loads in a new window.



Directions Developer's View

Step 1: Insert the below into the <head> section of your page:

Select All

Step 2: Finally, insert the below anywhere inside the <body> section of your page:

Select All

This script is extremely easy to customize. To edit the contents of the menu, simply change the text and urls of the code in Part 2. If you wish to change the physical width of the menu, change the width value inside the <style> tag of Part 1.

Each <div> supports a target attribute, which you define if you wish the particular menu link to launch in a different or new window. For example:

<div class="menuitems" url="index.htm">Dynamicdrive.com</div>
<div class="menuitems" url="new.htm" target="newwin">What's New?</div>
<div class="menuitems" url="hot.htm">What's Hot?</div>

This will cause the second link to be loaded in window "newwin".