禁止鼠標右鍵的幾種方法 第一種:笨方法
把下列代碼加入到<head>與</head>之間
<SCRIPT language=javascript>
function click() {
if (event.button==2) { // event.button==1 禁止鼠標左鍵
alert('禁止右鍵')
}
}
document.onmousedown=click
</SCRIPT>
第二種:添加至收藏夾
<SCRIPT language=JavaScript><!--
function click() {
if (event.button==2) {window.external.addFavorite('http://www.phpx.com','中國PHP聯盟')}}
document.onmousedown=click
// --></SCRIPT>
第三種:使鼠標右鍵無響應。 僅 IE5 適用,取消菜單顯示
把<BODY>改成<BODY oncontextmenu=self.event.returnValue=false>
第四種:鼠標失效 適用IE
ondragstart="window.event.returnValue=false"
oncontextmenu="window.event.returnValue=false"
onselectstart="event.returnValue=false"
把上面源代碼復制到<body>中就可以鎖定鼠標,讓訪客無法選定網頁內容進行復制。即使從IE瀏覽器“編輯”菜單下選取“全選”都沒用喲。
第五種:最聰明的方法,自己定制鼠標的右鍵菜單,給訪問者以全新的感受!
第一步:把代碼加入到<head>與</head>之間
<style>
<!--
/*
Context menu Script-
c Dynamic Drive
Last updated: 99/09/16th
For full source code, 100's more DHTML scripts, and Terms Of Use,
visit dynamicdrive.com
*/
#ie5menu{
position:absolute;
width:200px;
border:2px solid black;
background-color:menu;
font-family:Verdana;
line-height:20px;
cursor:default;
visibility:hidden;
}
.menuitems{
padding-left:15px;
padding-right:15px;
}
-->
</style>
<script language="JavaScript1.2">
//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0
function showmenuie5(){
var rightedge=document.body.clientWidth-event.clientX
var bottomedge=document.body.clientHeight-event.clientY
if (rightedge<ie5menu.offsetWidth)
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
else
ie5menu.style.left=document.body.scrollLeft+event.clientX
if (bottomedge>ie5menu.offsetHeight)
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
else
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
return false
}
function hidemenuie5(){
ie5menu.style.visibility="hidden"
}
function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}
function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status='
}
}
function jumptoie5(){
if (event.srcElement.className=="menuitems")
window.location=event.srcElement.url
}
</script>
第二步:把下列代碼加入到<body>與</body>之間
<!--[if IE]>
<div id="ie5menu" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
<hr>
<div class="menuitems" url="http://www.phpx.com">中國PHP聯盟</div>
</div>
<![endif]-->
<script language="JavaScript1.2">
document.oncontextmenu=showmenuie5
if (document.all&&window.print)
document.body.onclick=hidemenuie5
</script>