在WEB页中定制鼠标右键菜单 document.oncontextmenu = return false; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 脚本说明: 把如下代码加入<body>区域中 <script language="javaScript"><!-- menuItems = new Array(); menuItemNum = 0; function addMenuItem(text, url, img){ if(img) menuItems[menuItemNum] = new Array(text, url, img); else if(text) menuItems[menuItemNum] = new Array(text, url); else menuItems[menuItemNum] = new Array(); menuItemNum++; } menuWidth = 109; //menu width menuHeight = 176; //menu height menuDelay = 50; //delay before menu appears menuSpeed = 8; //speed which menu appears (lower=faster) menuOffset = 2; //offset of menu from mouse pointer addMenuItem("<center>csdn</center>","http://csdn.net"); addMenuItem(); addMenuItem("Killer.tK","http://www.killerj.tk"); /////////////////////////////////////////////////////////////////////////////// // do not edit the code below, it is required for the menu to work correctly /////////////////////////////////////////////////////////////////////////////// if(window.navigator.appName == "Microsoft Internet Explorer" && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5) isIe = 1; else isIe = 0; if(isIe){ menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" style="font:menu;color:menutext;"><tr height="1"><td style="background:threedlightshadow" colspan="4"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight" colspan="2"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="10"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"><table cellspacing="0" cellpadding="0" nowrap style="font:menu;color:menutext;cursor:default;">'; for(m=0;m<menuItems.length;m++){ if(menuItems[m][0] && menuItems[m][2]) menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap><img src="' + menuItems[m][2] + '"></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>'; else if(menuItems[m][0]) menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>'; else menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5"><table cellspacing="0"><tr><td width="2" height="1"></td><td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1"></td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight"></td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>'; } menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>'; menuPopup = window.createPopup(); menuPopup.document.body.innerHTML = menuContent; } function showMenu(){ menuXPos = event.clientX + menuOffset; menuYPos = event.clientY + menuOffset; menuXIncrement = menuWidth / menuSpeed; menuYIncrement = menuHeight / menuSpeed; menuTimer = setTimeout("openMenu(0,0)", menuDelay); return false; } function openMenu(height, width){ iHeight = height; iWidth = width; menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body); if(iHeight < menuHeight) menuTimer = setTimeout("openMenu(iHeight + menuYIncrement, iWidth + menuXIncrement)", 1); else clearTimeout(menuTimer); } if(isIe) document.oncontextmenu = showMenu;//--></script> <body oncontextmenu = "return false;"><script language=javascript>function document.onmouseup(){ if(event.button==2){ alert(1) return false;}}</script></body> 用function类型变量的toString方法获取其源码 alert() 这个方法伤不起啊! js 动态增加多行问题。帮帮忙,在线等。。急! Jquer幻灯片修改出现的问题 在js中两页面间怎样传递参数 控制文本框输入? 我想在网站上放一些三维动画,让用户观赏,但不能下载,该怎么做?100分不够再加 frame里如何重定向到另一个地址并跳出frame 怎样查看字段名 数组的forEach方法里面调用onclick方法 ●●●●●●●●●●●●关于层的隐藏!!!谢谢●●●●●●●●●●●● 日期问题,大侠指教
把如下代码加入<body>区域中
<script language="javaScript">
<!--
menuItems = new Array();
menuItemNum = 0; function addMenuItem(text, url, img){
if(img) menuItems[menuItemNum] = new Array(text, url, img);
else if(text) menuItems[menuItemNum] = new Array(text, url);
else menuItems[menuItemNum] = new Array();
menuItemNum++;
} menuWidth = 109; //menu width
menuHeight = 176; //menu height
menuDelay = 50; //delay before menu appears
menuSpeed = 8; //speed which menu appears (lower=faster)
menuOffset = 2; //offset of menu from mouse pointer addMenuItem("<center>csdn</center>","http://csdn.net");
addMenuItem();
addMenuItem("Killer.tK","http://www.killerj.tk");
///////////////////////////////////////////////////////////////////////////////
// do not edit the code below, it is required for the menu to work correctly
///////////////////////////////////////////////////////////////////////////////
if(window.navigator.appName == "Microsoft Internet Explorer" && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5)
isIe = 1;
else
isIe = 0; if(isIe){
menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" style="font:menu;color:menutext;"><tr height="1"><td style="background:threedlightshadow" colspan="4"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight" colspan="2"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="10"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"><table cellspacing="0" cellpadding="0" nowrap style="font:menu;color:menutext;cursor:default;">';
for(m=0;m<menuItems.length;m++){
if(menuItems[m][0] && menuItems[m][2])
menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap><img src="' + menuItems[m][2] + '"></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';
else if(menuItems[m][0])
menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'threedface\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';
else
menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5"><table cellspacing="0"><tr><td width="2" height="1"></td><td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1"></td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight"></td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>';
}
menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>'; menuPopup = window.createPopup();
menuPopup.document.body.innerHTML = menuContent;
} function showMenu(){
menuXPos = event.clientX + menuOffset;
menuYPos = event.clientY + menuOffset; menuXIncrement = menuWidth / menuSpeed;
menuYIncrement = menuHeight / menuSpeed; menuTimer = setTimeout("openMenu(0,0)", menuDelay); return false;
}
function openMenu(height, width){
iHeight = height;
iWidth = width; menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body); if(iHeight < menuHeight)
menuTimer = setTimeout("openMenu(iHeight + menuYIncrement, iWidth + menuXIncrement)", 1);
else
clearTimeout(menuTimer);
}
if(isIe) document.oncontextmenu = showMenu;
//-->
</script>
<script language=javascript>
function document.onmouseup()
{
if(event.button==2)
{ alert(1)
return false;
}
}
</script>
</body>