http://lucky.myrice.com/xml/xmlcontextmenu.html
解决方案 »
- 菜鸟求助:如何让文本框不能输入任何东西
- 如何用正则,从第一张图片中提取第一张
- reload和refresh的联系与区别
- CSS菜单问题.
- 怎样判断一个字符串里含有"&"符号?然后将它替换成“$” ?
- 问一个jk写的动态明细示例的问题?
- 如何检测是否运行在UNIT平台上的 Navigator 2 中
- 按鼠标右键的时候,可以先执行object的onmousedown;然后在执行document_oncontextmenu()
- javascript中使用多层的菜单后出现不同浏览器效果不同的原因?
- 如何在页面中响应<回车>???
- 如何屏蔽系统右键菜单,显示自己的菜单?
- 急!!!关于树形结构中金额栏求和问题
function Click(){
alert('hehe~ ~ ~ ');
window.event.returnValue=false;
}
document.oncontextmenu=Click;
< /Script>
帮你等一下,等待高手回复~
<script language=javascript>demo.document.designMode="on";</script><object id=DHTML classid=clsid:2D360201-FFF5-11D1-8D03-00A0C959BC0A" VIEWASTEXT></object>
<script language="javascript" for="DHTML" event="ShowContextMenu">
alert("你点击了鼠标右键!hehe!");
</script><script language=javascript>
function document.demo.document.oncontextmenu()
{
alert("你在 Iframe 里点击了鼠标右键!hehe!");
return false; //屏蔽系统的右键菜单
}
</script>
<iframe name=demo id=demo></iframe>
</body><script>demo.document.designMode="on";</script><script>function demo.document.oncontextmenu(){alert("hehe!");return false;}</script><script>
function init(memo)
{
// demo.document.write(memo);
demo.document.close();
demo.focus();
}
</script>
<head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312>
<title></title>
</head>
<body topmargin="0" onload="init('我在iframe中!!')">
<iframe name="demo"></iframe>
</body>
</html>
<script language="javascript">
var htmlheader='<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><html><body topmargin="0" bgcolor="#DAE7EF" leftmargin="0" oncontextmenu="return false"></body></html>';function init(memo) {
demo.document.designMode="off";
demo.document.open();
demo.document.write(htmlheader);
demo.document.write(memo);
demo.document.close();
demo.focus();
}
</script>
可我用它是来实现在线编辑的,一关闭,就不能在线编辑了。旭老大,还有没有别的法子。
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 5.50.4916.2300" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId>
<STYLE>.menutable {
BORDER-RIGHT: #307ce8 1px solid; BORDER-TOP: #94bcf3 1px solid; FONT-SIZE: 12px; Z-INDEX: 100; BORDER-LEFT: #307ce8 5px solid; BORDER-BOTTOM: #307ce8 1px solid; POSITION: absolute; BACKGROUND-COLOR: #ffffff
}
.menutrin {
CURSOR: hand; COLOR: #ffffff; BACKGROUND-COLOR: #1a71e6
}
.menutrout {
CURSOR: hand; COLOR: #000000
}
.menutd0 {
WIDTH: 28px; HEIGHT: 25px; TEXT-ALIGN: center; 改变这个修改菜单高度---:
}
.menutd1 {
WIDTH: 46px; FONT-FAMILY: Webdings; TEXT-ALIGN: right
}
.linktd1 {
WIDTH: 46px
}
.menutd2 {
WIDTH: 4px
}
.menuhr {
BORDER-RIGHT: #307ce8 1px inset; BORDER-TOP: #307ce8 1px inset; BORDER-LEFT: #307ce8 1px inset; BORDER-BOTTOM: #307ce8 1px inset
}
</STYLE>
<BGSOUND id=theBS src="" loop=0></HEAD>
<BODY style="FONT-SIZE: 10pt" bgColor=#eaf5fd>
<!----
/*-----------------------------------------------------------
鼠标右键菜单 1.0 Designed By Stroll e-mail: csy-163@163.com--------------------------------------------------------------*/
//--------------- 有关数据 -----------------//
var IconList = new Array(); // icon图片 集合, 下标从 1 开始
IconList[1] = new Image();
IconList[1].src = "icon/sub.gif";
//---------------- 检测变量 菜单的显示隐藏就靠它了!!! ------------------//
var JustMenuID = "";
var SubMenuList = new Array();
var NowSubMenu = "";
var mouseCanSound = true; //--------------------------- 声音开关 ------ 声音开关 ------------------//
//------------- 构建 主菜单 对象 -------------//
function MouseMenu(objName)
{
this.id = "Menu_"+objName;
this.obj = objName;
this.length = 0;
this.addMenu = addMenu;
this.addLink = addLink;
this.addHR = addHR;
JustMenuID = this.id;
document.body.insertAdjacentHTML('beforeEnd','<table id="'+this.id+'" border="0" cellspacing="0" cellpadding="0" style="top: 0; left: 0; display: none;" class="menutable" onmousedown=event.cancelBubble=true; onmouseup=event.cancelBubble=true></table>');
}
//----------- 构建 子菜单 对象 -------------//
function SubMenu(objName,objID)
{
this.obj = objName;
this.id = objID;
this.addMenu = addMenu;
this.addLink = addLink;
this.addHR = addHR;
this.length = 0;
}//-------------- 生成 菜单 makeMenu 方法 -----------//
function makeMenu(subID,oldID,word,icon,url,target,thetitle)
{
var thelink = '';
if(icon&&icon!="")
{
icon = '<img border="0" src="'+IconList[icon].src+'">';
}
else
{
icon = '';
}
if(!thetitle||thetitle=="")
{
thetitle = '';
}
if(url&&url!="")
{
thelink += '<a href="'+url+'" ';
if(target&&target!="")
{
thelink += ' ';
thelink += 'target="'+target+'" '
}
thelink += '></a>';
}
var Oobj = document.getElementById(oldID);
/*--------------------------------------------- 菜单html样式
<tr class="menutrout" id="trMenu_one_0" title="I am title">
<td class="menutd0"><img src="icon/sub.gif" border="0" width="16" height="16"></td>
<td><a href="javascript:alert('I am menu');" target="_self"></a><nobr>菜单一</nobr></td>
<td class="menutd1">4</td>
<td class="menutd2"> </td>
</tr>
--------------------------------------------------*/
with(Oobj.rows(Oobj.rows.length-1))
{
id = "tr"+subID;
className = "menutrout";
title = thetitle;
}
eventObj = "tr"+subID;
eval(eventObj+'.attachEvent("onmouseover",MtrOver('+eventObj+'))');
eval(eventObj+'.attachEvent("onclick",MtrClick('+eventObj+'))');
var trObj = eval(eventObj);
for(i=0;i<4;i++)
{
trObj.insertCell();
}
with(Oobj.rows(Oobj.rows.length-1))
{
cells(0).className = "menutd0";
cells(0).innerHTML = icon;
cells(1).innerHTML = thelink+'<nobr>'+word+'</nobr>';
cells(2).className = "menutd1";
cells(2).innerHTML = "4";
cells(3).className = "menutd2";
cells(3).innerText = " ";
}
document.body.insertAdjacentHTML('beforeEnd','<table id="'+subID+'" border="0" cellspacing="0" cellpadding="0" style="top: 0; left: 0; display: none" class="menutable" onmousedown=event.cancelBubble=true; onmouseup=event.cancelBubble=true></table>');
}//---------------- 生成连接 makeLink 方法 ------------//
function makeLink(subID,oldID,word,icon,url,target,thetitle)
{
var thelink = '';
if(icon&&icon!="")
{
icon = '<img border="0" src="'+IconList[icon].src+'">';
}
else
{
icon = '';
}
if(!thetitle||thetitle=="")
{
thetitle = '';
}
if(url&&url!="")
{
thelink += '<a href="'+url+'" ';
if(target&&target!="")
{
thelink += ' ';
thelink += 'target="'+target+'" '
}
thelink += '></a>';
}
var Oobj = document.getElementById(oldID);
/*--------------------------------------------- 连接html样式
<tr class="menutrout" id="trMenu_one_0" title="I am title">
<td class="menutd0"><img src="icon/sub.gif" border="0" width="16" height="16"></td>
<td><a href="javascript:alert('I am link');" target="_self"></a><nobr>连接一</nobr></td>
<td class="linktd1"></td>
<td class="menutd2"> </td>
</tr>
--------------------------------------------------*/
Oobj.insertRow();
with(Oobj.rows(Oobj.rows.length-1))
{
id = "tr"+subID;
className = "menutrout";
title = thetitle;
}
eventObj = "tr"+subID;
eval(eventObj+'.attachEvent("onmouseover",LtrOver('+eventObj+'))');
eval(eventObj+'.attachEvent("onmouseout",LtrOut('+eventObj+'))');
eval(eventObj+'.attachEvent("onclick",MtrClick('+eventObj+'))');
var trObj = eval(eventObj);
for(i=0;i<4;i++)
{
trObj.insertCell();
}
with(Oobj.rows(Oobj.rows.length-1))
{
cells(0).className = "menutd0";
cells(0).innerHTML = icon;
cells(1).innerHTML = thelink+'<nobr>'+word+'</nobr>';
cells(2).className = "linktd1";
cells(2).innerText = " ";
cells(3).className = "menutd2";
cells(3).innerText = " ";
}
}//-------------- 菜单对象 addMenu 方法 ------------//
function addMenu(word,icon,url,target,title)
{
var subID = this.id + "_" + this.length;
var subObj = this.obj+"["+this.length+"]";
var oldID = this.id;
eval(subObj+"= new SubMenu('"+subObj+"','"+subID+"')");
makeMenu(subID,oldID,word,icon,url,target,title);
this.length++;
}//------------- 菜单对象 addLink 方法 -------------//
function addLink(word,icon,url,target,title)
{
var subID = this.id + "_" + this.length;
var oldID = this.id;
makeLink(subID,oldID,word,icon,url,target,title);
this.length++;
}
//------------ 菜单对象 addHR 方法 -----------------//
function addHR()
{
var oldID = this.id;
var Oobj = document.getElementById(oldID);
Oobj.insertRow();
/*------------------------------------------
<tr>
<td colspan="4">
<hr class="menuhr" size="1" width="95%">
</td>
</tr>
--------------------------------------------*/
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/designmode.asp
看一下microsoft的标准
搞了半天,原来是这么回事,
你到我的网站上去看看,如果满意,我把源码奉上!
http://www.p5w.com.cn/bbs.asp
打开任意一个贴子,然后点右键看看。
看看
效果一下的
这个试试。
如果觉得行,我把源码奉上,然后你根据提示改改
_______________________________________________________
<SCRIPT language=javascript>
TableColor='#A7E0FC';
function DrawMouseMenu(rootId,Id){
DivH=2;
oSelection = document.selection;
var HrStr="<tr><td align=center valign=middle height=2><TABLE border=0 cellpadding=0 cellspacing=0 width=108 height=2><tr><td height=1 bgcolor=buttonshadow><\/td><\/tr><tr><td height=1 bgcolor=buttonhighlight><\/td><\/tr><\/TABLE><\/td><\/tr>";
var MenuStr1="<tr><td align=center valign=middle height=20><TABLE border=0 cellpadding=0 cellspacing=0 width=112><tr><td valign=middle height=16 class=Mout onMouseOver=this.className='Mover'; onMouseOut=this.className='Mout'; onclick=\"";
var MenuStr2="<\/td><\/tr><\/TABLE><\/td><\/tr>";
var Menu1=["document.newbbsfrm.mtext.focus()\">回复本贴","self.location='todaybbs.asp';\">最新文章"];
var Menu2=["self.location='hgqj.asp';\">宏观全景","MM_showHideLayers('Layer3','','hide');MM_showHideLayers('Layer2','','hide');MM_showHideLayers('Layer1','','show');self.location='qjxm.asp';\">全景相马","MM_showHideLayers('Layer3','','hide');MM_showHideLayers('Layer1','','hide');MM_showHideLayers('Layer2','','show');self.location='ghjg.asp';\">股海景观","MM_showHideLayers('Layer3','','show');MM_showHideLayers('Layer1','','hide');MM_showHideLayers('Layer2','','hide');self.location='qjfj.asp';\">全景风景","self.location='qjtz.asp';\">全景投资"]; SysMenu=["document.execCommand('SelectAll')\">全选","window.print()\">打印","window.close()\">关闭窗口"];
var MenuStr="";
for(i=0;i<Menu1.length;i++){
MenuStr+=MenuStr1+Menu1[i]+MenuStr2;
DivH+=20;
}
MenuStr+=HrStr;
for(i=0;i<Menu2.length;i++){
MenuStr+=MenuStr1+Menu2[i]+MenuStr2;
DivH+=20;
//if(i==0){MenuStr+=HrStr};
}
if(Menu2.length>0){
MenuStr+=HrStr;
DivH+=2;
}
for(i=0;i<SysMenu.length;i++){
MenuStr+=MenuStr1+SysMenu[i]+MenuStr2;
DivH+=20;
}
var DivStr1="<DIV id=MouseMenu class=div1 style=\"position:absolute; left:0px; top:0px; width=130;height="+DivH+"; z-index:1; visibility:hidden;\"><TABLE border=0 cellpadding=0 cellspacing=0 class=div2><tr><td bgcolor="+TableColor+" width=18 valign=center align=center bgcolor=buttonface><img id=menugif src=images/menu.gif width=18 height=220><\/td><td bgcolor=buttonface><TABLE border=0 cellpadding=0 cellspacing=0>";
var DJSoft="<tr><td height=20 align='center' valign='bottom'><table width=100% border=0 cellpadding=0 cellspacing=0><tr><td align='center' valign='bottom' bgcolor='#FFFFFF'><img border='0' src='images/p5wlogo.gif'><font color=#000000> 全景论坛</font><\/td><\/tr><\/table><\/td><\/tr>"; var DivStr2="<\/TABLE><\/td><\/tr><\/TABLE><\/DIV>";
document.write(DivStr1+MenuStr+DJSoft+DivStr2);
document.body.oncontextmenu=new Function("return ShowMouseMenu();");
document.body.onclick=new Function("MouseMenu.style.visibility='hidden';");
document.body.onscroll=new Function("MouseMenu.style.visibility='hidden';");
document.body.onselectstart=new Function("MouseMenu.style.visibility='hidden';");
window.onresizestart=new Function("MouseMenu.style.visibility='hidden';");
}
function ShowMouseMenu(){
if(MouseMenu.style.visibility=='visible')MouseMenu.style.visibility='hidden';
if(event.srcElement.tagName=="IMG"&&event.srcElement.id!="menugif"||event.srcElement.tagName=="A"||event.srcElement.tagName=="TEXTAREA"||event.srcElement.tagName=="INPUT"||oSelection.type!="None")
return true;
else{
if(event.clientX+150 > document.body.clientWidth)MouseMenu.style.left=event.clientX+document.body.scrollLeft-150;
else MouseMenu.style.left=event.clientX+document.body.scrollLeft;
if(event.clientY+DivH > document.body.clientHeight)MouseMenu.style.top=event.clientY+document.body.scrollTop-DivH;
else MouseMenu.style.top=event.clientY+document.body.scrollTop;
MouseMenu.style.visibility='visible';
}
return false;
}
DrawMouseMenu(32784,32784);
</SCRIPT>
<SCRIPT language=JavaScript>
<!--
function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
function showlayer()
{
MM_showHideLayers('Layer4','','hide');
MM_showHideLayers('Layer3','','hide');
MM_showHideLayers('Layer2','','hide');
MM_showHideLayers('Layer1','','show');
}</SCRIPT>
____________________________________________
禁用左右的代码如下
把如下代码加入<head>中
<script language="javascript">
function click(){
if (event.button==1){//改成button==2为禁右键
alert('对不起,禁止使用此键。')
}
}
document.onmousedown=click
</script>
<script language="JavaScript">
<!--if (window.Event)
document.captureEvents(Event.MOUSEUP); function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;return false;
}function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}}document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
<HTML><HEAD><TITLE>自定义鼠标右键弹出式菜单</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>.div1 {
BORDER-RIGHT: windowframe 1px solid; BORDER-TOP: buttonface 1px solid; BORDER-LEFT: buttonface 1px solid; BORDER-BOTTOM: windowframe 1px solid
}
.div2 {
BORDER-RIGHT: buttonshadow 1px solid; BORDER-TOP: window 1px solid; BORDER-LEFT: window 1px solid; BORDER-BOTTOM: buttonshadow 1px solid
}
.MouseOver {
FONT-SIZE: 12px; CURSOR: hand; COLOR: highlighttext; BACKGROUND-COLOR: highlight
}
.MouseOut {
FONT-SIZE: 12px; CURSOR: default; COLOR: buttontext; BACKGROUND-COLOR: buttonface
}
</STYLE><SCRIPT language=javascript>
function PopupMouseRightButtonUpMenu()
{
if(MouseMenu.style.visibility=='visible') MouseMenu.style.visibility='hidden';
if (event.srcElement.tagName=='A' || event.srcElement.tagName=='TEXTAREA' || event.srcElement.tagName=='INPUT' || document.selection.type!='None')
return true;
else
{
if (event.clientX+150 > document.body.clientWidth) MouseMenu.style.left=event.clientX+document.body.scrollLeft-150;
else MouseMenu.style.left=event.clientX+document.body.scrollLeft;
if (event.clientY+DivH > document.body.clientHeight) MouseMenu.style.top=event.clientY+document.body.scrollTop-DivH;
else MouseMenu.style.top=event.clientY+document.body.scrollTop;
MouseMenu.style.visibility='visible';
}
return false;
}
function DrawMouseRightButtonUpMenu(){
DivH=2;
//oSelection = document.selection;
var HrStr='<tr><td align=\"center\" valign=\"middle\" height=\"2\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"128\" height=\"2\"><tr><td height=\"1\" bgcolor=\"buttonshadow\"><\/td><\/tr><tr><td height=\"1\" bgcolor=\"buttonhighlight\"><\/td><\/tr><\/TABLE><\/td><\/tr>';
var MenuItemStr1='<tr><td align=\"center\" valign=\"middle\" height=\"20\"><TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"132\"><tr><td valign=\"middle\" height=\"16\" class=\"MouseOut\" onMouseOver=\"this.className=\'MouseOver\'\" onMouseOut=\"this.className=\'MouseOut\'\" onclick=\"'
var MenuItemStr2="<\/td><\/tr><\/TABLE><\/td><\/tr>";
var historyMenu=['window.history.back()\">后退','window.history.forward()\">前进'];
var SysMenu=['\">查找 <INPUT TYPE=\"text\" Size=\"10\" onkeypress=\"if (event.keyCode == 13) {MouseMenu.style.visibility=\'hidden\';var temp = this.value; this.value = \'\';return findInPage(temp)}\";\'>',
'document.execCommand(\'SelectAll\')\">全选',
'MouseMenu.style.visibility=\'hidden\';document.execCommand(\'SaveAs\',\'true\')\">另存为 ...',
'location.replace(\'view-source:\'+location.href)\">查看源文件',
'MouseMenu.style.visibility=\'hidden\';window.print()\">打印',
'window.location.reload()\">刷新'];var MenuStr='';
for(i=0;i<historyMenu.length;i++)
{
MenuStr+=MenuItemStr1+historyMenu[i]+MenuItemStr2;
DivH+=20;
}
MenuStr+=HrStr;
for(i=0;i<arguments.length;i++)
{
MenuStr+=MenuItemStr1+arguments[i]+MenuItemStr2;
DivH+=20;
}if(arguments.length>0)
{
MenuStr+=HrStr;
DivH+=2;
}for(i=0;i<SysMenu.length;i++)
{
MenuStr+=MenuItemStr1+SysMenu[i]+MenuItemStr2;
DivH+=20;
}var aboutMenu=['MouseMenu.style.visibility=\'hidden\';alert(\'http:\/\/www.playyuer.com\\nmailto:[email protected]\')">关于 ...']
MenuStr+=HrStr;
for(i=0;i<aboutMenu.length;i++)
{
MenuStr+=MenuItemStr1+aboutMenu[i]+MenuItemStr2;
DivH+=20;
}var MenuTop = '<DIV id=\"MouseMenu\" class=\"div1\" style=\"position:absolute; left:0px; top:0px; width=150;height='+DivH+'; z-index:1; visibility:hidden;\">\n' +
'<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"div2\">\n' +
'<tr>\n' +
'<td bgcolor=\"' + MenuBarColor+ '\" width=\"50\" valign=\"bottom\" align=\"center\" bgcolor=\"buttonface\">\n' +
'<\/td>\n'+
'<td bgcolor=\"buttonface\">\n'+
'<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\">';
var MenuBottom = '<\/TABLE><\/td><\/tr><\/TABLE><\/DIV>';
document.write(MenuTop+MenuStr+MenuBottom);
//prompt('aa',MenuTop+MenuStr+MenuBottom)
document.body.oncontextmenu=new Function('return PopupMouseRightButtonUpMenu();');
document.body.onclick=new Function('if(event.srcElement.tagName !=\'INPUT\') MouseMenu.style.visibility=\'hidden\'');
document.body.onscroll=new Function('MouseMenu.style.visibility=\'hidden\';');
document.body.onselectstart=new Function('MouseMenu.style.visibility=\'hidden\';');
window.onresizestart=new Function('MouseMenu.style.visibility=\'hidden\';');
}
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == '')
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert('文档搜索完毕。');
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart('character', 1);
txt.moveEnd('textedit');
}
if (found) {
txt.moveStart('character', -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert('文档搜索完毕。');
}
}
return false;
}
</SCRIPT><META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY>自定义鼠标右键弹出式菜单
<SCRIPT language=JavaScript>
<!--
var MenuBarColor ='#6600FF';
DrawMouseRightButtonUpMenu();
//-->
</SCRIPT>
</BODY></HTML>
<HTML><HEAD><TITLE>右键菜单</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
FONT-SIZE: 9pt
}
TABLE {
FONT-SIZE: 9pt; MARGIN: 0px; CURSOR: default
}
TR {
HEIGHT: 20px
}
TR.over {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #66aadd
}
TR.out {
FONT-SIZE: 9pt; CURSOR: default; COLOR: #ffffff; BACKGROUND-COLOR: #336699
}
DIV.rm_div {
BORDER-RIGHT: #3377aa 2px outset; BORDER-TOP: #3377aa 2px outset; DISPLAY: none; FILTER: Alpha(Opacity='95'); BORDER-LEFT: #3377aa 2px outset; WIDTH: 0px; BORDER-BOTTOM: #3377aa 2px outset; POSITION: absolute; HEIGHT: 0px; BACKGROUND-COLOR: #336699
}
HR.sperator {
BORDER-RIGHT: #3377aa 1px inset; BORDER-TOP: #3377aa 1px inset; BORDER-LEFT: #3377aa 1px inset; BORDER-BOTTOM: #3377aa 1px inset
}
</STYLE><SCRIPT language=JScript>
<!--
function RightMenu()
{
this.AddExtendMenu=AddExtendMenu;
this.AddItem=AddItem;
this.GetMenu=GetMenu;
this.HideAll=HideAll;
this.I_OnMouseOver=I_OnMouseOver;
this.I_OnMouseOut=I_OnMouseOut;
this.I_OnMouseUp=I_OnMouseUp;
this.P_OnMouseOver=P_OnMouseOver;
this.P_OnMouseOut=P_OnMouseOut;
A_rbpm = new Array();
HTMLstr = "";
HTMLstr += "<!-- RightButton PopMenu -->\n";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Starts -->\n";
HTMLstr += "<div id='E_rbpm' class='rm_div'>\n";
// rbpm = right button pop menu
HTMLstr += "<table width='100%' border='0' cellspacing='0'>\n";
HTMLstr += "<!-- Insert A Extend Menu or Item On Here For E_rbpm -->\n";
HTMLstr += "</table>\n";
HTMLstr += "</div>\n";
HTMLstr += "<!-- Insert A Extend_Menu Area on Here For E_rbpm -->";
HTMLstr += "\n";
HTMLstr += "<!-- PopMenu Ends -->\n";
}
function AddExtendMenu(id,name,parent)
{
var TempStr = "";
if(HTMLstr.indexOf("<!-- Extend Menu Area : E_"+id+" -->") != -1)
{
alert("E_"+id+"already exist!");
return;
}
eval("A_"+parent+".length++");
eval("A_"+parent+"[A_"+parent+".length-1] = id"); // 将此项注册到父菜单项的ID数组中去
TempStr += "<!-- Extend Menu Area : E_"+id+" -->\n";
TempStr += "<div id='E_"+id+"' class='rm_div'>\n";
TempStr += "<table width='100%' border='0' cellspacing='0'>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+id+" -->";
TempStr += "</table>\n";
TempStr += "</div>\n";
TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+id+" -->";
TempStr += "<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend_Menu Area on Here For E_"+parent+" -->",TempStr);
eval("A_"+id+" = new Array()");
TempStr = "";
TempStr += "<!-- Extend Item : P_"+id+" -->\n";
TempStr += "<tr id='P_"+id+"' class='out'";
TempStr += " onmouseover='P_OnMouseOver(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseout='P_OnMouseOut(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseup=window.event.cancelBubble=true;";
TempStr += " onclick=window.event.cancelBubble=true;";
TempStr += "><td nowrap>";
TempStr += " "+name+" </td><td style='font-family: webdings; text-align: right;'>";
TempStr += "</td></tr>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
}function AddItem(id,name,parent,location)
{
var TempStr = "";
var ItemStr = "<!-- ITEM : I_"+id+" -->";
if(id == "sperator")
{
TempStr += ItemStr+"\n";
TempStr += "<tr style='height: 3;' class='out' onclick='window.event.cancelBubble=true;' onmouseup='window.event.cancelBubble=true;'><td colspan='2'><hr class='sperator'></td></tr>";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
return;
}
if(HTMLstr.indexOf(ItemStr) != -1)
{
alert("I_"+id+"already exist!");
return;
}
TempStr += ItemStr+"\n";
TempStr += "<tr id='I_"+id+"' class='out'";
TempStr += " onmouseover='I_OnMouseOver(\""+id+"\",\""+parent+"\")'";
TempStr += " onmouseout='I_OnMouseOut(\""+id+"\")'";
TempStr += " onclick='window.event.cancelBubble=true;'";
if(location == null)
TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",null)'";
else
TempStr += " onmouseup='I_OnMouseUp(\""+id+"\",\""+parent+"\",\""+location+"\")'";
TempStr += "><td nowrap>";
TempStr += " "+name+" ";
TempStr += "</td><td></td></tr>\n";
TempStr += "<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->";
HTMLstr = HTMLstr.replace("<!-- Insert A Extend Menu or Item On Here For E_"+parent+" -->",TempStr);
}
function GetMenu()
{
return HTMLstr;
}
function I_OnMouseOver(id,parent)
{
var Item;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
Item = eval("I_"+id);
Item.className="over";
HideAll(parent,1);
}
function I_OnMouseOut(id)
{
var Item;
Item = eval("I_"+id);
Item.className="out";
}
function I_OnMouseUp(id,parent,location)
{
var ParentMenu;
window.event.cancelBubble=true;
OnClick();
ParentMenu = eval("E_"+parent);
ParentMenu.display="none";
if(location == null)
eval("Do_"+id+"()");
else
window.open(location);
}
function P_OnMouseOver(id,parent)
{
var Item;
var Extend;
var Parent;
if(parent != "rbpm")
{
var ParentItem;
ParentItem = eval("P_"+parent);
ParentItem.className="over";
}
HideAll(parent,1);
Item = eval("P_"+id);
Extend = eval("E_"+id);
Parent = eval("E_"+parent);
Item.className="over";
Extend.style.display="block";
Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth-4;
if(Extend.style.posLeft+Extend.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
Extend.style.posLeft=Extend.style.posLeft-Parent.offsetWidth-Extend.offsetWidth+8;
if(Extend.style.posLeft < 0) Extend.style.posLeft=document.body.scrollLeft+Parent.offsetLeft+Parent.offsetWidth;
Extend.style.posTop=Parent.offsetTop+Item.offsetTop;
if(Extend.style.posTop+Extend.offsetHeight > document.body.scrollTop+document.body.clientHeight)
Extend.style.posTop=document.body.scrollTop+document.body.clientHeight-Extend.offsetHeight;
if(Extend.style.posTop < 0) Extend.style.posTop=0;
}
function P_OnMouseOut(id,parent)
{
}
function HideAll(id,flag)
{
var Area;
var Temp;
var i;
if(!flag)
{
Temp = eval("E_"+id);
Temp.style.display="none";
}
Area = eval("A_"+id);
if(Area.length)
{
for(i=0; i < Area.length; i++)
{
HideAll(Area[i],0);
Temp = eval("E_"+Area[i]);
Temp.style.display="none";
Temp = eval("P_"+Area[i]);
Temp.className="out";
}
}
}
document.onmouseup=OnMouseUp;
document.onclick=OnClick;
function OnMouseUp()
{
if(window.event.button == 2)
{
var PopMenu;
PopMenu = eval("E_rbpm");
HideAll("rbpm",0);
PopMenu.style.display="block";
PopMenu.style.posLeft=document.body.scrollLeft+window.event.clientX;
PopMenu.style.posTop=document.body.scrollTop+window.event.clientY;
if(PopMenu.style.posLeft+PopMenu.offsetWidth > document.body.scrollLeft+document.body.clientWidth)
PopMenu.style.posLeft=document.body.scrollLeft+document.body.clientWidth-PopMenu.offsetWidth;
if(PopMenu.style.posLeft < 0) PopMenu.style.posLeft=0;
if(PopMenu.style.posTop+PopMenu.offsetHeight > document.body.scrollTop+document.body.clientHeight)
PopMenu.style.posTop=document.body.scrollTop+document.body.clientHeight-PopMenu.offsetHeight;
if(PopMenu.style.posTop < 0) PopMenu.style.posTop=0;
}
}
function OnClick()
{
HideAll("rbpm",0);
}
// Add Your Function on following
function Do_viewcode(){window.location="view-source:"+window.location.href;}
function Do_help(){window.showHelp(window.location);}
function Do_exit() {window.close();}
function Do_refresh() {window.location.reload();}
function Do_back() {history.back();}
function Do_forward() {history.forward();}
function Do_author(){alert("姓名:杨俊\n网名:风舞影天(Snwcwt)\nE_mail:[email protected]\n个人主页:http://202.115.147.160/snwcwt(正在制作中)\n")}
-->
</SCRIPT><META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY oncontextmenu=window.event.returnValue=false>
<DIV id=snwcwt> </DIV>
<SCRIPT language=JScript>
<!--
var menu = new RightMenu();
menu.AddExtendMenu("location","我的链接","rbpm");
menu.AddExtendMenu("lscit","四川工业学院校园网","location");
menu.AddItem("scit_scit","川工首页","lscit","http://www.scit.edu.cn");
menu.AddItem("scit_lib","川工图书馆","lscit","http://202.115.151.46");
menu.AddItem("sperator","","lscit",null);
menu.AddItem("scit_century","世纪学苑","lscit","http://202.115.148.230/");
menu.AddItem("scit_the5","第五空间","lscit","http://the5.scit.edu.cn/");
menu.AddItem("scit_lianyi","联谊网站","lscit","http://202.115.148.240");
menu.AddItem("scit_message","信息导报","lscit","http://202.115.151.114/xx");
menu.AddItem("scit_student","书生之家川工境象","lscit","http://202.115.151.100");
menu.AddItem("sperator","","lscit",null);
menu.AddItem("scit_bbs","川工BBS","lscit","http://202.115.144.32");
menu.AddItem("scit_cbbs","世纪学苑BBS","lscit","http://202.115.144.37");
menu.AddExtendMenu("stunet","学生网站","location");
menu.AddItem("stu_century","世纪学苑","stunet","http://202.115.148.230/");
menu.AddItem("stu_wjl","望江楼","stunet","http://wjl.scu.edu.cn");
menu.AddItem("stu_freedim","自由天地","stunet","http://www.freedim.net/");
menu.AddItem("stu_stuhome","学生之家","stunet","http://www.stuhome.net");
menu.AddItem("stu_rw","人文网","stunet","http://www.rw.uestc.edu.cn/");
menu.AddItem("stu_the5","第五空间","stunet","http://the5.scit.edu.cn/");
menu.AddItem("stu_flying","我心飞扬","stunet","http://flying.swpi.edu.cn/");
menu.AddItem("stu_21cn","21CN校园网","stunet","http://www.21cn.edu.cn/");
menu.AddItem("stu_yaguo","网虫乐园","stunet","http://www.yaguo.com/");
menu.AddItem("sperator","","location",null);
menu.AddExtendMenu("computer","电脑类网站","location");
menu.AddExtendMenu("C_all","综合性网站","computer");
menu.AddItem("ca_yesky","天极网","C_all","http://www.yesky.com");
menu.AddExtendMenu("C_program","程序员网站","computer");
menu.AddItem("cp_program","中国程序员网站","C_program","http://www.chinaprogrammer.com/");
menu.AddItem("sperator","","C_program",null);
menu.AddItem("cp_51js","无忧脚本","C_program","http://www.51js.com/");
menu.AddItem("sperator","","C_program",null);
menu.AddItem("cp_active","中国动感技术网络","C_program","http://www.chinaasp.com/active/");
menu.AddItem("cp_aspcn","ASP中华网","C_program","http://www.aspcn.com/");
menu.AddItem("cp_aspx","中国ASP联盟","C_program","http://www.chinaspx.com/");
menu.AddExtendMenu("C_magzine","杂志网站","computer");
menu.AddItem("cm_cpcw","电脑报","C_magzine","http://www.cpcw.com");
menu.AddItem("cm_cfan","电脑爱好者","C_magzine","http://www.cfan.net.cn");
menu.AddItem("cm_popsoft","大众软件","C_magzine","http://www.popsoft.com");
menu.AddExtendMenu("C_luntan","技术性论坛","computer");
menu.AddItem("cl_chinaasp","ChinaASP论坛","C_luntan","http://www.chinaasp.com/sqlbbs");
menu.AddExtendMenu("C_book","书籍下载","computer");
menu.AddItem("cb_huachu","华储网上书店","C_book","http://www.huachu.com.cn/");
menu.AddExtendMenu("hacker","黑客天地","location");
menu.AddItem("hk_honker","<font style='color: #ff0000;'>中国红客联盟</font>","hacker","http://www.cnhonker.com");
menu.AddItem("sperator","","location",null);
menu.AddExtendMenu("lmovie","影视天地","location");
menu.AddItem("mov_wcums","华西网上影院","lmovie","http://202.115.100.8/");
menu.AddExtendMenu("lmusic","音乐空间","location");
menu.AddItem("mus_tyfo","天虎音乐网","lmusic","http://music.tyfo.com/");
menu.AddItem("mus_langqin","浪琴音乐","lmusic","http://www.langqin.net/");
menu.AddItem("mus_wcums","华西音乐空间","lmusic","http://music.wcums.edu.cn/");
menu.AddExtendMenu("lmud","泥巴链接","location");
menu.AddItem("lmud_mudking","泥巴大王","lmud","http://www.mudking.com");
menu.AddItem("lmud_justmud","泥巴城堡","lmud","http://www.justmud.com");
menu.AddItem("lmud_mudall","世界泥巴资源","lmud","http://www.mudall.com");
menu.AddItem("lmud_yaguo","泥潭风云","lmud","http://202.114.98.14/mud/");
menu.AddItem("sperator","","location",null);
menu.AddExtendMenu("lemail","电子邮局","location");
menu.AddItem("email_263","263免费电子邮局","lemail","http://freemail.263.net");
menu.AddExtendMenu("collections","综合性网站","location");
menu.AddItem("coll_chinaren","中国人网站","collections","http://www.chinaren.com/");
menu.AddItem("coll_etang","亿唐网站","collections","http://www.etang.com/");
menu.AddItem("coll_263","263首都在线","collections","http://www.263.net/");
menu.AddExtendMenu("leave","离开","rbpm");
menu.AddItem("forward","前进","leave",null);
menu.AddItem("back","后退","leave",null);
menu.AddItem("sperator","","leave",null);
menu.AddItem("exit","退出","leave",null);
menu.AddItem("viewcode","查看源代码","rbpm",null);
menu.AddItem("refresh","刷新","rbpm",null);
menu.AddItem("sperator","","rbpm",null);
menu.AddItem("help","帮助","rbpm",null);
menu.AddItem("sperator","","rbpm",null);
menu.AddItem("author","<font style='color: #ff0000'>关于作者</font>","rbpm",null);
document.writeln(menu.GetMenu());
-->
</SCRIPT>
</BODY></HTML>
<head>
<style>
.menu{ cursor: hand;
display: none;
position: absolute;
top: 0; left: 0;
overflow: hidden;
background-color: "#CFCFCF";
border: "2 solid";
border-top-color: "#EFEFEF";
border-left-color: "#EFEFEF";
border-right-color: "#505050";
border-bottom-color: "#505050";
font: 10pt 宋体;
margin:0pt;padding: 2pt
}
.menu SPAN {width: 100%; cursor: hand; padding-left: 10pt;padding-bottom:2px}
.menu SPAN.selected {background: navy; color:white; cursor: hand;padding-top:2px}
</style>
<xml id="contextDef">
<xmldata>
<contextmenu id="demo">
<item id="viewsource" value="查看源文件"/>
<item id="back" value="后退……"/>
<item id="meng" value="访问【孟宪会之精彩世界】"/>
<item id="calculate" value="执行 JavaScript 代码"/>
</contextmenu>
<contextmenu id="demob">
<item id="菜单项例子1" value="菜单项例子1" />
<item id="菜单项例子2" value="菜单项例子2" />
</contextmenu>
</xmldata>
</xml>
<SCRIPT>
// 定义全局变量
var bContextKey=false;
function fnGetContextID(el) {
while (el!=null) {
if (el.contextmenu) return el.contextmenu
el = el.parentElement
}
return ""
}
function fnDetermine(){
oWorkItem=event.srcElement;
//键盘上的菜单键被按下时。
if(bContextKey==true){
//如果菜单的“状态”为“false”
if(oContextMenu.getAttribute("status")=="false"){
//捕获鼠标事件,以便和页面交互。
oContextMenu.setCapture();
//根据鼠标位置,确定菜单位置。
oContextMenu.style.top=event.clientY + document.body.scrollTop + 1;
oContextMenu.style.left=event.clientX + document.body.scrollLeft + 1;
oContextMenu.innerHTML="";
//设定菜单的“状态”为“true”
var sContext = fnGetContextID(event.srcElement)
if (sContext!="") {
fnPopulate(sContext)
oContextMenu.setAttribute("status","true");
event.returnValue=false;
}
else
event.returnValue=true
}
}
else{
// 如果键盘菜单键没有按下,并且菜单的“状态”为“true”。
if(oContextMenu.getAttribute("status")=="true"){
if((oWorkItem.parentElement.id=="oContextMenu") && (oWorkItem.getAttribute("component")=="menuitem"))
{
fnFireContext(oWorkItem)
}
// 当鼠标离开菜单或单击菜单项后,重设菜单(隐藏)
oContextMenu.style.display="none";
oContextMenu.setAttribute("status","false");
oContextMenu.releaseCapture();
oContextMenu.innerHTML="";
event.returnValue=false;
}
}
}
function fnPopulate(sID)
{
var str=""
var elMenuRoot =
document.all.contextDef.XMLDocument.childNodes(0).selectSingleNode('contextmenu[@id="' + sID + '"]'
)
if (elMenuRoot) {
for(var i=0;i<elMenuRoot.childNodes.length;i++)
str+='<span component="menuitem" menuid="' + elMenuRoot.childNodes[i].getAttribute("id") +'" id=oMenuItem' + i + '>' + elMenuRoot.childNodes[i].getAttribute("value") + "</SPAN><BR>"
oContextMenu.innerHTML=str;
oContextMenu.style.display="block";
oContextMenu.style.pixelHeight = oContextMenu.scrollHeight
}
}
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.className = "selected"
}
}
}
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.className = ""
}
}
}
function fnInit(){
if (oContextMenu) {
oContextMenu.style.width=180;
oContextMenu.style.height=document.body.offsetHeight/2;
oContextMenu.style.zIndex=2;
//设置菜单样式
document.oncontextmenu=fnSuppress;
}
}
function fnInContext(el) {
while (el!=null) {
if (el.id=="oContextMenu") return true
el = el.offsetParent
}
return false
}
function fnSuppress(){
if (!(fnInContext(event.srcElement))) {
oContextMenu.style.display="none";
oContextMenu.setAttribute("status","false");
oContextMenu.releaseCapture();
bContextKey=true;
}
fnDetermine();
bContextKey=false;
}
function javameng(){
window.open("http://lucky.myrice.com","_blank","width=400,height=400,top=20,left=20")
}
function fnFireContext(oItem) {
// 自定义上下文菜单项的功能
switch (oItem.menuid) {
case "viewsource":
location.href = "view-source:" + location.href
break;
case "back":
history.back()
break;
case "meng":
location.href="http://lucky.myrice.com"
break;
case "calculate":
javameng()
break;
default:
alert("你点击的菜单项是:\n\n\n" + oItem.menuid +"啊!!!")
}
}
</SCRIPT>
<BODY onload="fnInit()" onclick="fnDetermine()" bgcolor="#0099ff">
<p contextmenu="Title" align="center" style="font-size:11pt; font-weight:bold; border:3px double #000099;padding:10px">利用XML创建上下文菜单<br><br>【<a href="http://lucky.myrice.com" style="font-size:9pt;font-weight:normal">孟宪会之精彩世界</a>】</p>
<div status="false" onmouseover="fnChirpOn()" onmouseout="fnChirpOff()" id="oContextMenu" class="menu"></div>这里放你任意的其他的东西!这个地方没有菜单!!!<br><br>
<P contextmenu="demo">这里是利用上下文菜单的里子!你把鼠标移动到这里,然后单击鼠标又键,可以看到菜单内容!<br>这里是利用上下文菜单的里子!你把鼠标移动到这里,然后单击鼠标又键,可以看到菜单内容!<br>这里是利用上下文菜单的里子!你把鼠标移动到这里,然后单击鼠标又键,可以看到菜单内容!<br>这里是利用上下文菜单的里子!你把鼠标移动到这里,然后单击鼠标又键,可以看到菜单内容!<br>这里是利用上下文菜单的里子!你把鼠标移动到这里,然后单击鼠标又键,可以看到菜单内容!<br></p><p>你也可以把鼠标放到下面的图象上面,点击又键!<p>
<center><IMG SRC="http://lucky.myrice.com/back.jpg" contextmenu="demob">
</body>
</html>
<!--
// menu object
function contextMenu()
{
this.items = new Array();
this.addItem = function (item)
{
this.items[this.items.length] = item;
} this.show = function (oDoc)
{
var strShow = "";
var i;
strShow = "<div id=\"rightmenu\" style=\"BACKGROUND-COLOR: #ffffff; BORDER: #000000 1px solid; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; Z-INDEX: 10\">";
strShow += "<table border=\"0\" height=\"";
strShow += this.items.length * 20;
strShow += "\" cellpadding=\"0\" cellspacing=\"0\">";
strShow += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\" width=\"2\"></td><td>";
strShow += "<table border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
strShow += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
strShow += "</td><td width=\"2\"></td></tr>";
strShow += "<tr><td bgcolor=\"#d0d0ce\"></td><td>";
strShow += "<table border=\"0\" width=\"100%\" height=\"100%\" cellpadding=3 cellspacing=0 bgcolor=\"#ffffff\">";
oDoc.write(strShow);
for(i=0; i<this.items.length; i++)
{
this.items[i].show(oDoc);
}
strShow = "</table></td><td></td></tr>";
strShow += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\"></td><td>";
strShow += "<table border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
strShow += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
strShow += "</td><td></td></tr>";
strShow += "</table></div>\n";
oDoc.write(strShow);
}
}// menu Item object
function contextItem(text, icon, cmd, type)
{
this.text = text ? text : "";
this.icon = icon ? icon : "";
this.cmd = cmd ? cmd : "";
this.type = type ? type : "menu";
this.show = function (oDoc)
{
var strShow = "";
if(this.type == "menu")
{
strShow += "<tr ";
strShow += "onmouseover=\"changeStyle(this, 'on');\" ";
strShow += "onmouseout=\"changeStyle(this, 'out');\" ";
strShow += "onclick=\"";
strShow += this.cmd;
strShow += "\">";
strShow += "<td class=\"ltdexit\" width=\"16\">";
if (this.icon == "")
strShow += " ";
else {
strShow += "<img border=\"0\" src=\"";
strShow += this.icon;
strShow += "\" width=\"16\" height=\"16\" style=\"POSITION: relative\"></img>";
}
strShow += "</td><td class=\"mtdexit\">";
strShow += this.text;
strShow += "</td><td class=\"rtdexit\" width=\"5\"> </td></tr>";
}
else if (this.type == "separator")
{
strShow += "<tr><td class=\"ltdexit\"> </td>";
strShow += "<td class=\"mtdexit\" colspan=\"2\"><hr color=\"#000000\" size=\"1\"></td></tr>";
}
oDoc.write(strShow);
}
}function changeStyle(obj, cmd)
{
if(obj) try {
var imgObj = obj.children(0).children(0);
if(cmd == 'on') {
obj.children(0).className = "ltdfocus";
obj.children(1).className = "mtdfocus";
obj.children(2).className = "rtdfocus";
if(imgObj)
{
if(imgObj.tagName.toUpperCase() == "IMG")
{
imgObj.style.left = "-1px";
imgObj.style.top = "-1px";
}
}
}
else if(cmd == 'out') {
obj.children(0).className = "ltdexit";
obj.children(1).className = "mtdexit";
obj.children(2).className = "rtdexit";
if(imgObj)
{
if(imgObj.tagName.toUpperCase() == "IMG")
{
imgObj.style.left = "0px";
imgObj.style.top = "0px";
}
}
}
}
catch (e) {}
}function showMenu()
{
var x, y, w, h, ox, oy;
x = event.clientX;
y = event.clientY;
var obj = document.getElementById("rightmenu");
if (obj == null)
return true;
ox = document.body.clientWidth;
oy = document.body.clientHeight;
if(x > ox || y > oy)
return false;
w = obj.offsetWidth;
h = obj.offsetHeight;
if((x + w) > ox)
x = x - w;
if((y + h) > oy)
y = y - h;
obj.style.posLeft = x + document.body.scrollLeft;
obj.style.posTop = y + document.body.scrollTop;
obj.style.visibility = "visible";
return false;
}
function hideMenu()
{
if(event.button == 0)
{
var obj = document.getElementById("rightmenu");
if (obj == null)
return true;
obj.style.visibility = "hidden";
obj.style.posLeft = 0;
obj.style.posTop = 0;
}
}function writeStyle()
{
var strStyle = "";
strStyle += "<STYLE type=text/css>";
strStyle += "TABLE {Font-FAMILY: \"Tahoma\",\"Verdana\",\"宋体\"; FONT-SIZE: 9pt}";
strStyle += ".mtdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; CURSOR: hand}";
strStyle += ".mtdexit {BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid}";
strStyle += ".ltdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; CURSOR: hand}";
strStyle += ".ltdexit {BACKGROUND-COLOR: #d0d0ce; BORDER-BOTTOM: #d0d0ce 1px solid; BORDER-TOP: #d0d0ce 1px solid; BORDER-LEFT: #d0d0ce 1px solid}";
strStyle += ".rtdfocus {BACKGROUND-COLOR: #ccccff; BORDER-BOTTOM: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; CURSOR: hand}";
strStyle += ".rtdexit {BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-RIGHT: #ffffff 1px solid}";
strStyle += "</STYLE>";
document.write(strStyle);
}function makeMenu()
{
var myMenu, item;
var homepage_cmd = "this.style.behavior='url(#default#homepage)';this.setHomePage('http://gamethinking.yeah.net/'); return false;";
var favorate_cmd = "window.external.addFavorite('http://gamethinking.yeah.net/','游戏思想'); return false;";
var viewcode_cmd = "window.location = 'view-source:' + window.location.href";
myMenu = new contextMenu();
item = new contextItem("返回主页", "images/main.gif", "top.location='http://gamethinking.yeah.net/';", "menu");
myMenu.addItem(item);
item = new contextItem("设为主页", "images/myhome.gif", homepage_cmd, "menu");
myMenu.addItem(item);
item = new contextItem("添加到收藏夹", "images/fav_add.gif", favorate_cmd, "menu");
myMenu.addItem(item);
item = new contextItem("联系作者", "images/mail.gif", "location.href='mailto:[email protected]'", "menu");
myMenu.addItem(item);
item = new contextItem("", "", "", "separator");
myMenu.addItem(item);
item = new contextItem("察看源码", "images/edit.gif", viewcode_cmd, "menu");
myMenu.addItem(item);
myMenu.show(this.document); delete item;
delete myMenu;
}function toggleMenu(isEnable)
{
if(isEnable)
document.oncontextmenu = showMenu;
else
document.oncontextmenu = new function() {return true;};
}writeStyle();
makeMenu();
document.onclick = hideMenu;
document.oncontextmenu = showMenu;
file://-->
<OBJECT
id=menu1
onmouseover="menu1.style.display=''"
style=" POSITION: ABSOLUTE;DISPLAY: none; Z-INDEX: 1000; HEIGHT: 200px"
onmouseout="menu1.style.display='none'"
type=text/x-scriptlet
data=caidan.htm
VIEWASTEXT>
</OBJECT>
<SCRIPT LANGUAGE=vbscript >
function document_oncontextmenu()
document_oncontextmenu=false
menu1.style.LEFT=window.event.x
menu1.style.TOP=window.event.y
menu1.style.display=""
end function
</SCRIPT>
文件2:
caidan.htm
<div style='position:absolute;left:0;top:0;width:152;height:200;font:14;color:white;background:black;border:1 solid black'>
<div onclick="alert(this.innerText)">菜单1</div>
<div onclick="alert(this.innerText)">菜单2</div>
<div onclick="alert(this.innerText)">菜单3</div>
<div onclick="alert(this.innerText)">菜单4</div>
<div onclick="alert(this.innerText)">菜单5</div>
<div onclick="alert(this.innerText)">菜单6</div>
<div onclick="alert(this.innerText)">菜单7</div>
</div>
演示:
www.adr.gov.cn/download/Rmenu.htm
这个菜单还有个好处,不会被<select>标签遮挡哦!~~
一般div不会有这个效果