不嫌麻烦的话可以运行下面的代码看看情况,这是msdn里面的一个例子:
<HTML>
<HEAD>
<TITLE>Creating Dynamic Context Menus</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-8859-1">
<META NAME="AUTHOR" CONTENT="InetSDK">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<style>
.menu{cursor: hand; left-margin:5px; display: none; cursor: hand; position: absolute; top: 0; left: 0; background-color: "#CFCFCF"; border: "1 solid"; border-top-color: "#EFEFEF"; border-left-color: "#EFEFEF"; border-right-color: "#505050"; border-bottom-color: "#505050"; font-size: 8pt; font-family: Arial;}
</style>
<script>
// Define global script variables
var iMenuItems=0;
var sData="";
var oContextObject="";
var bContextKey="false";// The fnDetermine function performs most of the workfunction fnDetermine(){
oWorkItem=event.srcElement;
window.status=oWorkItem.tagName; // Proceed if the desired keyboard key is pressed.
if(bContextKey==true){
// If the menu STATUS is false, continue.
if(oContextMenu.getAttribute("status")=="false"){
// Give the menu mouse capture so it can interact better with the page.
oContextMenu.setCapture(false); // Relocate the menu to an offset from the mouse position.
oContextMenu.style.top=event.clientY + 10;
oContextMenu.style.left=event.clientX + 10; // Provide a terse wait message while populating the menu.
oContextMenu.innerHTML="Stand By...";

// Make the menu visible.
oContextMenu.style.display="block";

// Wait a tenth of second before beginning, then flood the menu with properties and values from the selected object.
setTimeout("fnPopulate(oWorkItem)",100)  ; // Set its STATUS to true.
oContextMenu.setAttribute("status","true");
event.returnValue=false;
}
}
else{
// If the keyboard key was not pressed and the menu status is true, continue.
if(oContextMenu.getAttribute("status")=="true"){
// If the object that was clicked has the menu for a parent and it has a COMPONENT attribute equal to "menuitem", continue.
if((oWorkItem.parentElement.id=="oContextMenu")&&(oWorkItem.getAttribute("component")=="menuitem")){ // If this isn't the top line, acting as a title, then display the information.
if(oWorkItem.innerText.indexOf("Properties for")==-1){
alert("Status For Object: " + oContextObject.tagName + "\nProperty: " + oWorkItem.innerText + "\nValue: " + oContextObject.tagName + "." + oWorkItem.innerText + " = " + eval("oContextObject." + oWorkItem.innerText));
fnChirpOff();

} // Reset the context menu, release mouse capture, and hide it.
oContextMenu.style.display="none";
oContextMenu.setAttribute("status","false");
oContextMenu.releaseCapture();
oContextMenu.innerHTML="";
event.returnValue=false;
}
}
}

function fnPopulate(oTarget){
// Clear the context menu
oContextMenu.innerHTML="";
oContextObject=oTarget; // Use a counter for the menu items.
iMenuItems=0; // Add a menu title to identify the object.
fnAddItem(oContextMenu,"Properties for: <b>" + oTarget.tagName + "</b>"); // Loop through the object's properties and style attributes and add those with value to the context menu.
for(i in oTarget){
if((eval("oTarget." + i)!="[object]")&&(eval("oTarget." + i)!="")&&(eval("oTarget." + i)!=null)){
fnAddItem(oContextMenu,i);
}
}
for(i in oTarget.style){
if((eval("oTarget.style." + i)!="")&&(eval("oTarget.style." + i)!=null)){
fnAddItem(oContextMenu,"style." + i);
}
}
}function fnAddItem(oTargetGroup,sContent){
// The object and property is passed from the fnPopulate function and added to the context menu.
oTargetGroup.innerHTML+='<span component="menuitem" id=oMenuItem' + iMenuItems + '>' + sContent + '</span><br>';

// Increment the menu items at this time.
iMenuItems++;
}/* The chirp functions provide visual appeal.  Notice that they are specific about only changing styles while the mouse is within the client window.  This is because setCapture allows the mouse to pick up coordinate values on the window (not the user's screen) and this can throw an error if you try to get a property from an object that isn't recognized. */
function fnChirpOn(){
if((event.clientX>0)&&(event.clientY>0)&&(event.clientX<document.body.offsetWidth)&&(event.clientY<document.body.offsetHeight)){
oWorkItem=event.srcElement;
if(oWorkItem.getAttribute("component")=="menuitem"){
oWorkItem.style.backgroundColor="#FFFF00";
oWorkItem.style.color="#0000FF";
}
}
}
function fnChirpOff(){
if((event.clientX>0)&&(event.clientY>0)&&(event.clientX<document.body.offsetWidth)&&(event.clientY<document.body.offsetHeight)){
oWorkItem=event.srcElement;
if(oWorkItem.getAttribute("component")=="menuitem"){
oWorkItem.style.backgroundColor="#CFCFCF";
oWorkItem.style.color="#000000";
}
}
}function fnInit(){ // Setup the basic styles of the context menu.
oContextMenu.style.width=110;
oContextMenu.style.height=document.body.offsetHeight/2;
oContextMenu.style.overflow="auto";
oContextMenu.style.zIndex=2;
document.oncontextmenu=fnSuppress;
}
function fnSuppress(){
bContextKey=true;
fnDetermine();
bContextKey=false;
return false;
}
function fnLinkFunc(){
oLink.innerHTML='Im a link!';
}
</script><!-- SAMPLE_STYLE_START -->
<LINK REL="stylesheet" HREF="../../../../../workshop/basicsdkie4.css" TYPE="text/css">
<!-- SAMPLE_STYLE_END -->
</HEAD>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END--><BODY onload="fnInit()" onclick="fnDetermine()" TOPMARGIN=0 LEFTMARGIN=0 BGPROPERTIES="FIXED" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#808080" ALINK="#000000">
<BLOCKQUOTE CLASS="body"><!-- CONTENTS_START -->
<H1>Creating Dynamic Context Menus<hr size=1></H1>
   
<P>This sample demonstrates how to create a context menu that uses the <b>setCapture</b> and <b>releaseCapture</b> methods.
To create a context menu, the <a href="../../../../../workshop/author/dhtml/reference/events/oncontextmenu.htm">oncontextmenu</a> event is cancelled, preventing the default context menu from opening.</P><P>A context menu is created that lists all of the properties for the selected DHTML object.
Click on one of the listed properties to see its value.
When one of the properties is clicked, or when you click anywhere on the screen, the context menu will close.</P><div status="false" onmouseover="fnChirpOn()" onmouseout="fnChirpOff()" id="oContextMenu" class="menu">
</div>
<b>Things to get context menu information from:</b>
<p>
<b>Right-click for Context Menu</b>
<P>
<a id="oLink" href="javascript:alert('This is a sample link')">Right-click for Context Menu</a>
<!-- CONTENTS_END -->
<div id="fff">asdfasafsfasdf</div>
<!-- START_PAGE_FOOTER -->
<BR><BR><BR>
&copy; <A CLASS="clsIncCpyRt" HREF="http://msdn.microsoft.com/isapi/gomscom.asp?target=/misc/cpyright.htm" TARGET="_top">2000 Microsoft Corporation. All rights reserved. Terms of use</A>.
<!-- END_PAGE_FOOTER -->
</BLOCKQUOTE>
</BODY>
</HTML>