Post Print Search
帖子排序:    
帖子发起人: 中国IT网   发起时间: 2007-02-21 16:35 下午   回复: 1
ChinaIT.Com.CN 离线,最后访问时间: 2008-12-16 10:54:25 中国IT网

发帖数前10位

注册: 2005-09-20
发贴: 342
彻底屏蔽右键代码
楼主  2007-02-21, 16:35 下午 Reply Quote
第一种 禁止右键、Ctrl键和复制功能的JS代码 有的t网站页面禁止使用右键和复制功能,甚至连Ctrl键也禁止掉了,这个效果是如何实现的呢?其实很简单就是调用了一段JS代码而已。 下面文本框中就是实现效果所需代码: function click(e) { if (document.all) { if (event.button==1||event.button==2||event.button==3) { oncontextmenu='return false'; } } if (document.layers) { if (e.which == 3) { oncontextmenu='return false'; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=click; document.oncontextmenu = new Function("return false;") var travel=true var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */ if (document.layers) document.captureEvents(Event.KEYDOWN) function gogo(e) { if (document.layers) { if (e.which==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); } } else if (document.all){ if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }} } document.onkeydown=gogo 把上面的代码另存为一个JS文件,然后在想实现此效果的页面用<!--#include file="*.js" -->调用即可,*代表你另存的文件名! 第二种 禁用右键并自动导航 脚本说明: 把如下代码加入<body>区域中 <script language="javascript"> if (navigator.appName.indexOf("Internet Explorer") != -1) document.onmousedown = noSourceExplorer; function noSourceExplorer() { if (event.button == 2 | event.button == 3) { alert("禁止右键...去首页!"); location.replace("http://www.baidu.com"); } } </script> 第三种 禁用右键代码 将以下代码加到〈head〉与〈/head〉之间 <script language="JavaScript"> document.oncontextmenu=new Function("event.returnValue=false;"); document.onselectstart=new Function("event.returnValue=false;"); </script>
IP 地址: 已记录   报告
maxcfor 离线,最后访问时间: 2008-10-21 15:00:12 max

发帖数前500位

注册: 2008-10-21
发贴: 1
Wink [;)] Re: 彻底屏蔽右键代码
第2楼  2008-10-21, 15:00 下午 Reply Quote

谢谢 楼主 虽然时间有点久远  谢谢!

IP 地址: 已记录   报告
中国IT网 ChinaIT C... » China站长 » 新手学堂 » 彻底屏蔽右键代码

Powered by Community Server Powered by CnForums.Net