IE NC通用的藏鼠标右键一法

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 reve 的 blog

       首先,对于internet explorer的隐藏鼠标右键的方法,可以说只要弄过网页的人可能知道要用  document.oncontextmenu=function("return false;"); 不过对于netscape,这个办法就并不能完全行的通。通过实践,我发觉,在internet explorer和netscape这两款浏览器中都存在某些元素,鼠标的右键在上边点击是没有反应。现在我就利用如此一点来隐藏鼠标右键。我们可以知道在internet explorer和netscape这两款浏览器中<div>的滚动条上是弹不出右键菜单的,那我们就在右键事件中把我们定制的<div>元素just_hide_it移到鼠标的点击的位置来,这样就不可能弹出右键菜单了。

       源代码如下:

<html><head><meta http-equiv="content-type" content="text/html; charset=gb2312">
<!--
edited by renjian zhou(joo),shanghai jiao tong university,application mathematic,class f0007102.if you are interested in editing html pages,connected me by bombjet.joo@163.com.
-->
<title>
通用的藏鼠标右键
</title>
</head>
<body style="z-index:-1;">
<script language="javascript">
tmp=navigator.appversion.tostring();
ie=parsefloat(tmp.substring(tmp.indexof("msie")+4,tmp.length));
function nc_rightclick(e)
{
  if(e.button==2 || (e.button==0 && e.type=="contextmenu"))
  {
    document.getelementbyid('just_hide_it').style.left=e.clientx-14;
    document.getelementbyid('just_hide_it').style.top=e.clienty-14;
    return false;
  }
}
if(ie)
  document.oncontextmenu=function("return false;");
else
{
  document.write('<div id="just_hide_it" style="z-index:-1;position:absolute;left:100;top:0;overflow:scroll;width:28;height:28;"></div>');
  document.oncontextmenu=nc_rightclick;
  document.onmousedown=nc_rightclick;
}
</script>
</body>
</html>


       解释一下:不仅在netscape中可以用如此<div>方法,在internet explorer中<div>方法也有效,不过既然在internet explorer中已经有了更有效的方法,我也就不用如此方法了。在netscape中对just_hide_it要求z-index为-1与body的z-index相同是出于使just_hide_it透明化,使人感觉不出有如此一个元素的存在。

        再说一句,我们隐藏鼠标右键的目的不是藏源代码,而是为了一些其他的网页的功能。顺便提倡各位大虾,有好的代码,多点共享。毕竟这个世界应该是一个共享的世界。

 

本文关键:右键, 鼠标, 隐藏, Internet Explorer, Netscape
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top