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

来源:互联网 发布:淘宝主播招聘网 编辑:程序博客网 时间:2024/04/27 21:34
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

       首先,对于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透明化,使人感觉不出有如此一个元素的存在。

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

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击