打印本文 打印本文 关闭窗口 关闭窗口
禁止右键、Ctrl键和复制功能的JS代码
作者:武汉SEO闵涛  文章来源:敏韬网  点击数647  更新时间:2009/4/23 11:21:47  文章录入:mintao  责任编辑:mintao

  有的网站页面禁止使用右键和复制功能,甚至连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" -->调用即可,*代表你另存的文件名!

打印本文 打印本文 关闭窗口 关闭窗口