欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WEB页面上的内容防复制

程序员文章站 2022-03-03 09:07:47
...

html 写法: 

<html lang="en">
 <head>
   <meta charset="UTF-8">
   <title>防复制内容例子</title>
 </head>
 

 <body oncontextmenu="return false" ondragstart="return false" onselectstart="return false"   onbeforecopy="return false">
    防复制的内容

</body>
 </html>

js写法:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>文本防复制</title>
</head>

<body>
  文本防复制
  <script language=javascript>
      window.onload = function () {
        var element = document.body;
        element.oncontextmenu = function () {
          return false;
        }
        element.onselect = function () {
          return false;
        }
        element.onselectstart = function () {
          return false;
        }
        element.onbeforecopy = function () {
          return false;
        }
      }
  </script>
</body>
</html>