原码给你,好好看看吧!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0078)http://msdn.microsoft.com/workshop/samples/author/dhtml/refs/oncontextmenu.htm -->
<HTML><HEAD><TITLE>oncontextmenu Event Sample</TITLE>
<META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">
<META content=InetSDK name=AUTHOR>
<META content=EN-US name=MS.LOCALE>
<META content=noindex name=ROBOTS>
<STYLE>.menuItem {
PADDING-LEFT: 20px; FONT-SIZE: 10pt; WIDTH: 100px; COLOR: black; FONT-FAMILY: sans-serif; BACKGROUND-COLOR: menu
}
.highlightItem {
PADDING-LEFT: 20px; FONT-SIZE: 10pt; WIDTH: 100px; COLOR: white; FONT-FAMILY: sans-serif; BACKGROUND-COLOR: highlight
}
.clickableSpan {
BORDER-RIGHT: gray 5px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 5px solid; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: gray 5px solid; WIDTH: 500px; COLOR: white; PADDING-TOP: 4px; BORDER-BOTTOM: gray 5px solid; BACKGROUND-COLOR: blue
}
</STYLE><SCRIPT>
//<!--function displayMenu() {
whichDiv=event.srcElement;
menu1.style.leftPos+=10;
menu1.style.posLeft=event.clientX;
menu1.style.posTop=event.clientY;
menu1.style.display="";
menu1.setCapture();
}
function switchMenu() {
el=event.srcElement;
if (el.className=="menuItem") {
el.className="highlightItem";
} else if (el.className=="highlightItem") {
el.className="menuItem";
}
}
function clickMenu() {
menu1.releaseCapture();
menu1.style.display="none";
el=event.srcElement;
if (el.id=="mnuRed") {
whichDiv.style.backgroundColor="red";
} else if (el.id=="mnuGreen") {
whichDiv.style.backgroundColor="green";
} else if (el.id=="mnuBlue") {
whichDiv.style.backgroundColor="blue";
} else if (el.id=="mnuYellow") {
whichDiv.style.backgroundColor="yellow";
}
}//-->
</SCRIPT>
<!-- SAMPLE_STYLE_START --><LINK href="不显示系统菜单.files/basicSDKIE4.css"
type=text/css rel=stylesheet><!-- SAMPLE_STYLE_END --><!-- TOOLBAR_START --><!-- TOOLBAR_EXEMPT --><!--TOOLBAR_END-->
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY vLink=#808080 aLink=#000000 link=#000000 bgProperties=fixed
bgColor=#ffffff leftMargin=0 topMargin=0>
<BLOCKQUOTE class=body><!-- CONTENTS_START -->
<H1>oncontextmenu Event Sample</H1>
<P>This sample shows how to use the <B>oncontextmenu</B> event handler,
available in Microsoft?Internet Explorer 5 and later, to display both
standard and custom context menus and prevent context menus from displaying.
Experiment with each of the following boxes to see how you can apply different
methods either to display or to inhibit context menus. Each box provides
instructions for you to follow. </P><SPAN class=clickableSpan>1. The default
context menu always displays when you right-click in this box. <B><BR>Code:
</B>//no code necessary </SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="return event.ctrlKey">2. The default context menu displays only
if you right-click in this box while holding down the Ctrl key. This is useful
for developing and debugging purposes. <B><BR>Code: </B>oncontextmenu="return
event.ctrlKey" </SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="return false">3. A context menu never displays when you
right-click in this box. <B><BR>Code: </B>oncontextmenu="return false"
</SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="displayMenu();return false">4. A custom context menu displays
when you right-click in this box. <B><BR>Code:
</B>oncontextmenu="showMenu();return false;" </SPAN><BR><BR><SPAN
class=clickableSpan
oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}">5. A custom
menu displays when you right-click in this box. If you right-click while
holding down the Ctrl key, the default context menu displays. <B><BR>Code:
</B>oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"
</SPAN><BR>
<DIV id=menu1 onmouseover=switchMenu()
style="BORDER-RIGHT: gray 3px outset; BORDER-TOP: gray 3px outset; DISPLAY: none; BORDER-LEFT: gray 3px outset; WIDTH: 100px; BORDER-BOTTOM: gray 3px outset; POSITION: absolute; BACKGROUND-COLOR: menu"
onclick=clickMenu() onmouseout=switchMenu()>
<DIV class=menuItem id=mnuRed>Red</DIV>
<DIV class=menuItem id=mnuGreen>Green</DIV>
<DIV class=menuItem id=mnuBlue>Blue</DIV>
<DIV class=menuItem id=mnuYellow>Yellow</DIV></DIV><!-- CONTENTS_END --><!-- START_PAGE_FOOTER --><BR><BR><BR>?
<!-- END_PAGE_FOOTER --></BLOCKQUOTE></BODY></HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0078)http://msdn.microsoft.com/workshop/samples/author/dhtml/refs/oncontextmenu.htm -->
<HTML><HEAD><TITLE>oncontextmenu Event Sample</TITLE>
<META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">
<META content=InetSDK name=AUTHOR>
<META content=EN-US name=MS.LOCALE>
<META content=noindex name=ROBOTS>
<STYLE>.menuItem {
PADDING-LEFT: 20px; FONT-SIZE: 10pt; WIDTH: 100px; COLOR: black; FONT-FAMILY: sans-serif; BACKGROUND-COLOR: menu
}
.highlightItem {
PADDING-LEFT: 20px; FONT-SIZE: 10pt; WIDTH: 100px; COLOR: white; FONT-FAMILY: sans-serif; BACKGROUND-COLOR: highlight
}
.clickableSpan {
BORDER-RIGHT: gray 5px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 5px solid; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: gray 5px solid; WIDTH: 500px; COLOR: white; PADDING-TOP: 4px; BORDER-BOTTOM: gray 5px solid; BACKGROUND-COLOR: blue
}
</STYLE><SCRIPT>
//<!--function displayMenu() {
whichDiv=event.srcElement;
menu1.style.leftPos+=10;
menu1.style.posLeft=event.clientX;
menu1.style.posTop=event.clientY;
menu1.style.display="";
menu1.setCapture();
}
function switchMenu() {
el=event.srcElement;
if (el.className=="menuItem") {
el.className="highlightItem";
} else if (el.className=="highlightItem") {
el.className="menuItem";
}
}
function clickMenu() {
menu1.releaseCapture();
menu1.style.display="none";
el=event.srcElement;
if (el.id=="mnuRed") {
whichDiv.style.backgroundColor="red";
} else if (el.id=="mnuGreen") {
whichDiv.style.backgroundColor="green";
} else if (el.id=="mnuBlue") {
whichDiv.style.backgroundColor="blue";
} else if (el.id=="mnuYellow") {
whichDiv.style.backgroundColor="yellow";
}
}//-->
</SCRIPT>
<!-- SAMPLE_STYLE_START --><LINK href="不显示系统菜单.files/basicSDKIE4.css"
type=text/css rel=stylesheet><!-- SAMPLE_STYLE_END --><!-- TOOLBAR_START --><!-- TOOLBAR_EXEMPT --><!--TOOLBAR_END-->
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY vLink=#808080 aLink=#000000 link=#000000 bgProperties=fixed
bgColor=#ffffff leftMargin=0 topMargin=0>
<BLOCKQUOTE class=body><!-- CONTENTS_START -->
<H1>oncontextmenu Event Sample</H1>
<P>This sample shows how to use the <B>oncontextmenu</B> event handler,
available in Microsoft?Internet Explorer 5 and later, to display both
standard and custom context menus and prevent context menus from displaying.
Experiment with each of the following boxes to see how you can apply different
methods either to display or to inhibit context menus. Each box provides
instructions for you to follow. </P><SPAN class=clickableSpan>1. The default
context menu always displays when you right-click in this box. <B><BR>Code:
</B>//no code necessary </SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="return event.ctrlKey">2. The default context menu displays only
if you right-click in this box while holding down the Ctrl key. This is useful
for developing and debugging purposes. <B><BR>Code: </B>oncontextmenu="return
event.ctrlKey" </SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="return false">3. A context menu never displays when you
right-click in this box. <B><BR>Code: </B>oncontextmenu="return false"
</SPAN><BR><BR><SPAN class=clickableSpan
oncontextmenu="displayMenu();return false">4. A custom context menu displays
when you right-click in this box. <B><BR>Code:
</B>oncontextmenu="showMenu();return false;" </SPAN><BR><BR><SPAN
class=clickableSpan
oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}">5. A custom
menu displays when you right-click in this box. If you right-click while
holding down the Ctrl key, the default context menu displays. <B><BR>Code:
</B>oncontextmenu="if (!event.ctrlKey){displayMenu();return false;}"
</SPAN><BR>
<DIV id=menu1 onmouseover=switchMenu()
style="BORDER-RIGHT: gray 3px outset; BORDER-TOP: gray 3px outset; DISPLAY: none; BORDER-LEFT: gray 3px outset; WIDTH: 100px; BORDER-BOTTOM: gray 3px outset; POSITION: absolute; BACKGROUND-COLOR: menu"
onclick=clickMenu() onmouseout=switchMenu()>
<DIV class=menuItem id=mnuRed>Red</DIV>
<DIV class=menuItem id=mnuGreen>Green</DIV>
<DIV class=menuItem id=mnuBlue>Blue</DIV>
<DIV class=menuItem id=mnuYellow>Yellow</DIV></DIV><!-- CONTENTS_END --><!-- START_PAGE_FOOTER --><BR><BR><BR>?
<!-- END_PAGE_FOOTER --></BLOCKQUOTE></BODY></HTML>
<html>
<head>
<STYLE>
.skin0 {
BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; VISIBILITY: hidden;
BORDER-LEFT: black 1px solid; WIDTH: 150px; CURSOR: default; LINE-HEIGHT: 1px; BORDER-BOTTOM:
black 1px solid; FONT-FAMILY: Verdana; POSITION: absolute; BACKGROUND-COLOR: black; TEXT-ALIGN:left
}
.skin1 {
BORDER-RIGHT: buttonhighlight 0px outset; BORDER-TOP: buttonhighlight 0px outset;
FONT-SIZE: 9pt; VISIBILITY: hidden; BORDER-LEFT: buttonhighlight 0px outset; WIDTH: 120px;
CURSOR: default; BORDER-BOTTOM: buttonhighlight 0px outset; FONT-FAMILY: Arial, Helvetica,
sans-serif; POSITION: absolute; BACKGROUND-COLOR: #000000; TEXT-ALIGN: center
}
.menuitems {PADDING-RIGHT: 10px; PADDING-LEFT: 10px}
</STYLE>
</head>
<script>
function showit(){
var display_url="0"
var rightedge=document.body.clientWidth-event.clientX
var topedge=document.body.clientHeight-event.clientY
if(rightedge<dandan.offsetWidth)
dandan.style.left=document.body.scrollLeft+event.clientX-dandan.offsetWidth
else
dandan.style.left=document.body.scrollLeft+event.clientX
if(topedge<dandan.offsetHeight)
dandan.style.top=document.body.scrollTop+event.clientY-dandan.offsetHeight
else
dandan.style.top=document.body.scrollTop+event.clientY
dandan.style.visibility="visible"
return false
}
function hiddenit(){
dandan.style.visibility="hidden"
}
function spring(){
if (event.srcElement.className == "menuitems") {
if (event.srcElement.getAttribute("target") != null)
window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
else
window.location = event.srcElement.href;
}
}
function lowlightie5(){}
function highlightie5(){}</script>
<body>
<div id="dandan" class="skin0" style="Left:280;Top:28;" onclick="spring();event.cancelBubble=true" onmouseout=lowlightie5() onmouseover=highlightie5()>
<ul><center>
<li><b>导航菜单<b></li>
<li><a href="http://www.163.com">论坛</a></li>
<li><a href="http://www.sohu.com">江湖</a></li>
<li><a href="http://www.sina.com">电影</a></li>
<li><a href="http://www.china,com">flash</a></li></center>
</ul>
</div>
<script>
if(document.all && window.print){
dandan.className = "skin1";
document.oncontextmenu = showit
document.body.onclick = hiddenit;
}
</script>
</body>
</html>