liuqingxia

摘要

为了保护我们的代码,我们需要想些办法禁止复制。

css:

body{

    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
     user-select: none;

}

js:

oncontextmenu  事件禁用网页点击右键

document.oncontextmenu = function(){

    event.returnValue = false;

}

//或者直接返回整个事件

document.oncontextmenu = function(){

      return  false;

}

onselectstart  事件禁用网页上选取内容

document.onselectstart = function(){

    event.returnValue = false;

}

//或者直接返回整个事件

document.onselectstart = function(){

      return  false;

}

oncopy 事件禁用复制

document.oncopy= function(){

    event.returnValue = false;

}

//或者直接返回整个事件

 

document.oncopy= function(){

 

    return false;

 

}

以上三种事件,也可直接写在body上:

<body oncontextmenu = " return false"></body>

<body onselectstart = " return false"></body>

<body oncopy = " return false"></body>

 

 

以上的方法差强人意,对于精通电脑的人来说,这样是不合格的写法

且键盘F12也可以查看源代码复制;

所以从根本上禁止复制的方法必须解决:禁止键盘F12

 

document.onkeydown = function () {
   if (window.event && window.event.keyCode == 123) {
         event.keyCode = 0;
         event.returnValue = false;
         return false;
   }
};

 

 

搬运工:http://www.cnblogs.com/happiness-mumu/p/6269465.html

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-11-03
  • 2021-12-31
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-10-24
  • 2021-12-31
  • 2021-12-31
相关资源
相似解决方案