当前位置: 首页 > java >正文

禁止鼠标右键的几种方法


第一种:常用方法
<script language="javascript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnvalue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnvalue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu;  // for IE5+
document.onmousedown = norightclick;  // for all others
//-->
</script>


第二种:笨方法

把下列代码加入到<head>与</head>之间
<SCRIPT language=javascript>
  function click() {
  if (event.button==2) { // event.button==1 禁止鼠标左键
  alert('禁止右键')
  }
  }
  document.οnmοusedοwn=click
  </SCRIPT>

第三种:添加至收藏夹

<SCRIPT language=JavaScript><!--
function click() {
if (event.button==2) {window.external.addFavorite('http://www.phpx.com','中国PHP联盟')}}
document.οnmοusedοwn=click
// --></SCRIPT>

第四种:使鼠标右键无响应。 仅 IE5 适用,取消菜单显示

把<BODY>改成<BODY οncοntextmenu=self.event.returnValue=false>


第五种:鼠标失效 适用IE

οndragstart="window.event.returnValue=false"
οncοntextmenu="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.οncοntextmenu=showmenuie5
if (document.all&&window.print)
document.body.οnclick=hidemenuie5
</script>

转载于:https://www.cnblogs.com/ioricc/archive/2005/10/27/263242.html

http://www.xdnf.cn/news/11028.html

相关文章:

  • 国企面试题:如果有第八号当铺,你愿意拿什么换这个offer?
  • 国内知名站长网站 ChinaZ 论坛宣布关闭
  • Android的HTTP方式网络通信----HttpClient
  • 基于MATLAB的CT直接反投影算法的实验研究
  • 蓝牙技术
  • Hibernate初学者教程
  • 【小松教你手游开发】【unity实用技能】 unity 接WP8 sdk的一些心得
  • suse日常操作(含suse/rhel内核与发行版对应关系)
  • 手把手教你如何破解无线网络密码(蹭网教程)
  • Ubuntu 7.10 Server 安装 Desktop
  • 软件破解脱壳法
  • Jolicloud试用记——网络、游戏和总结
  • 软件问题定义及可行性分析——数据字典
  • 仅需 5 步,用 JavaScript 直接通过前端发送电子邮件
  • 【探花交友】day05—圈子互动
  • vbs无限循环代码_vbs整人代码
  • Web挖掘技术
  • 【值得收藏的种子搜索引擎】
  • VC开发指南--Visual C++/MFC入门教程
  • 老司机是怎么找到资源的,掌握这些搜索技巧,全网资源都是你的
  • 10款精选的后台管理系统
  • 分享88个NET源码,总有一款适合您
  • kali无线渗透之WEP加密模式与破解13_wep加密过程详解,2024年最新被面试官问的网络安全-Framework难倒了
  • 最好的磁盘管理工具Acronis Disk Director Suite 10.0的强大功能介绍
  • 最新Viking(维金)病毒专杀工具,纯VB编写。
  • 密码破解之RADIUS-CHAP-MD5
  • Buffer overrun detected!
  • win7下修改注册表问题 模块jscript.dll已加载,但对DllRegisterServer的调用失败,错误代码为0x80004005 我是WIN7
  • 万年历算法介绍(C代码)
  • SecureCRT for Mac:安全、可靠的终端仿真软件,让数据传输更放心