禁止鼠标右键的几种方法

<p >第一种:常用方法<br /> &lt;script language=&quot;javascript&quot;&gt;<br /> &lt;!--<br /> if (window.Event)<br /> document.captureEvents(Event.MOUSEUP);<br /> function nocontextmenu()<br /> {<br /> event.cancelBubble = true<br /> event.returnvalue = false;<br /> return false;<br /> }<br /> function norightclick(e)<br /> {<br /> if (window.Event)<br /> {<br /> if (e.which == 2 || e.which == 3)<br /> return false;<br /> }<br /> else<br /> if (event.button == 2 || event.button == 3)<br /> {<br /> event.cancelBubble = true<br /> event.returnvalue = false;<br /> return false;<br /> }<br /> }<br /> document.oncontextmenu = nocontextmenu; // for IE5+<br /> document.onmousedown = norightclick; // for all others<br /> //--&gt;<br /> &lt;/script&gt;</p> <p >第二种:笨方法</p> <p >把下列<span class="wp_keywordlink" ><a href="http://www.xuebuyuan.com/" target="_blank" title="代码">代码</a></span>加入到&lt;head&gt;与&lt;/head&gt;之间<br /> &lt;SCRIPT language=javascript&gt;<br />   function click() {<br />   if (event.button==2) { // event.button==1 禁止鼠标左键<br />   alert(&#39;禁止右键&#39;)<br />   }<br />   }<br />   document.onmousedown=click<br />   &lt;/SCRIPT&gt;</p> <p >第三种:添加至收藏夹</p> <p >&lt;SCRIPT language=JavaScript&gt;&lt;!--<br /> function click() {<br /> if (event.button==2) {window.external.addFavorite(&#39;http://www.phpx.com&#39;,&#39;中国PHP联盟&#39;)}}<br /> document.onmousedown=click<br /> // --&gt;&lt;/SCRIPT&gt;</p> <p >第四种:使鼠标右键无响应。 仅 IE5 适用,取消菜单显示</p> <p >把&lt;BODY&gt;改成&lt;BODY oncontextmenu=self.event.returnValue=false&gt;</p> <p >第五种:鼠标失效 适用IE</p> <p >ondragstart=&quot;window.event.returnValue=false&quot;<br /> oncontextmenu=&quot;window.event.returnValue=false&quot;<br /> onselectstart=&quot;event.returnValue=false&quot;<br /> 把上面<span class="wp_keywordlink" ><a href="http://www.xuebuyuan.com/" target="_blank" title="源代码">源代码</a></span>复制到&lt;body&gt;中就可以锁定鼠标,让访客无法选定网页内容进行复制。即使从IE浏览器&ldquo;编辑&rdquo;菜单下选取&ldquo;全选&rdquo;都没用哟。</p> <p >第六种:最聪明的方法,自己定制鼠标的右键菜单,给访问者以全新的感受!</p> <p >第一步:把代码加入到&lt;head&gt;与&lt;/head&gt;之间<br /> &lt;style&gt;<br /> &lt;!--<br /> /*<br /> Context menu Script-<br /> c Dynamic Drive<br /> Last updated: 99/09/16th<br /> For full source code, 100&#39;s more DHTML scripts, and Terms Of Use,<br /> visit dynamicdrive.com<br /> */<br /> #ie5menu{<br /> position:absolute;<br /> width:200px;<br /> border:2px solid black;<br /> background-color:menu;<br /> font-family:Verdana;<br /> line-height:20px;<br /> cursor:default;<br /> visibility:hidden;<br /> }<br /> .menuitems{<br /> padding-left:15px;<br /> padding-right:15px;<br /> }<br /> --&gt;<br /> &lt;/style&gt;<br /> &lt;script language=&quot;JavaScript1.2&quot;&gt;<br /> //set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar<br /> var display_url=0<br /> function showmenuie5(){<br /> var rightedge=document.body.clientWidth-event.clientX<br /> var bottomedge=document.body.clientHeight-event.clientY<br /> if (rightedge&lt;ie5menu.offsetWidth)<br /> ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth<br /> else<br /> ie5menu.style.left=document.body.scrollLeft+event.clientX<br /> if (bottomedge&gt;ie5menu.offsetHeight)<br /> ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight<br /> else<br /> ie5menu.style.top=document.body.scrollTop+event.clientY<br /> ie5menu.style.visibility=&quot;visible&quot;<br /> return false<br /> }<br /> function hidemenuie5(){<br /> ie5menu.style.visibility=&quot;hidden&quot;<br /> }<br /> function highlightie5(){<br /> if (event.srcElement.className==&quot;menuitems&quot;){<br /> event.srcElement.style.backgroundColor=&quot;highlight&quot;<br /> event.srcElement.style.color=&quot;white&quot;<br /> if (display_url==1)<br /> window.status=event.srcElement.url<br /> }<br /> }<br /> function lowlightie5(){<br /> if (event.srcElement.className==&quot;menuitems&quot;){<br /> event.srcElement.style.backgroundColor=&quot;&quot;<br /> event.srcElement.style.color=&quot;black&quot;<br /> window.status=&#39;&#39;<br /> }<br /> }<br /> function jumptoie5(){<br /> if (event.srcElement.className==&quot;menuitems&quot;)<br /> window.location=event.srcElement.url<br /> }<br /> &lt;/script&gt;<br /> 第二步:把下列代码加入到&lt;body&gt;与&lt;/body&gt;之间<br /> &lt;!--[if IE]&gt;<br /> &lt;div id=&quot;ie5menu&quot; onMouseover=&quot;highlightie5()&quot; onMouseout=&quot;lowlightie5()&quot; onClick=&quot;jumptoie5()&quot;&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;hr&gt;<br /> &lt;div class=&quot;menuitems&quot; url=&quot;<a href="http://www.phpx.com/" >http://www.phpx.com</a>&quot;&gt;中国PHP联盟&lt;/div&gt;<br /> &lt;/div&gt;<br /> &lt;![endif]--&gt;<br /> &lt;script language=&quot;JavaScript1.2&quot;&gt;<br /> document.oncontextmenu=showmenuie5<br /> if (document.all&amp;&amp;window.print)<br /> document.body.onclick=hidemenuie5<br /> &lt;/script&gt;</p>
RangeTime:0.006380s
RangeMem:211.54 KB
返回顶部 留言