中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 精文荟萃 > 经验技巧
禁止鼠标右键的几种方法
作者:佚名 时间:2005-05-18 11:22 出处:互连网 责编:chinaitpower
              摘要:禁止鼠标右键的几种方法

禁止鼠标右键的几种方法 第一种:笨方法

把下列代码加入到<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>


以上资料是 wxffwxff 收集积累起来的,现拿出来与各位共享。
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有