熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

IENC通用的藏鼠標右鍵一法

2022-06-13   來源: JSP教程 

  首先對於Internet Explorer的隱藏鼠標右鍵的方法可以說只要弄過網頁的人可能知道要用 documentoncontextmenu=Function(return false;); 不過對於Netscape這個辦法就並不能完全行的通通過實踐我發覺在Internet Explorer和Netscape這兩款浏覽器中都存在某些元素鼠標的右鍵在上邊點擊是沒有反應現在我就利用如此一點來隱藏鼠標右鍵我們可以知道在Internet Explorer和Netscape這兩款浏覽器中<div>的滾動條上是彈不出右鍵菜單的那我們就在右鍵事件中把我們定制的<div>元素just_hide_it移到鼠標的點擊的位置來這樣就不可能彈出右鍵菜單了

  源代碼如下

  <html><head><meta httpequiv=ContentType content=text/html; charset=gb>
<!
Edited by Renjian Zhou(Joo)Shanghai Jiao Tong UniversityApplication MathematicClass FIf you are interested in editing HTML pagesconnected me by
>
<title>
通用的藏鼠標右鍵
</title>
</head>
<body >
<script language=JavaScript>
tmp=navigatorappVersiontoString();
IE=parseFloat(tmpsubstring(tmpindexOf(MSIE)+tmplength));
function NC_rightclick(e)
{
if(ebutton== || (ebutton== && etype==contextmenu))
{
  documentgetElementById(just_hide_it)styleleft=eclientX;
  documentgetElementById(just_hide_it)styletop=eclientY;
  return false;
}
}
if(IE)
documentoncontextmenu=Function(return false;);
else
{
documentwrite(<div id=just_hide_it ></div>);
documentoncontextmenu=NC_rightclick;
documentonmousedown=NC_rightclick;
}
</script>
</body>
</html>

  解釋一下不僅在Netscape中可以用如此<div>方法在Internet Explorer中<div>方法也有效不過既然在Internet Explorer中已經有了更有效的方法我也就不用如此方法了在Netscape中對just_hide_it要求zIndex為與body的zindex相同是出於使just_hide_it透明化使人感覺不出有如此一個元素的存在

  再說一句我們隱藏鼠標右鍵的目的不是藏源代碼而是為了一些其他的網頁的功能順便提倡各位大蝦有好的代碼多點共享畢竟這個世界應該是一個共享的世界


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19547.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.