網頁禁止複製的兩種方式
阿新 • • 發佈:2018-12-06
兩種方式:
1.檢測到點選複製時直接return false
2.直接禁用右鍵
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>網頁禁止複製的2種方式</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="//cdn.bootcss.com/layer/3.0.1/layer.min.js"></script> <style type="text/css"> body .layui-layer-hui .layui-layer-content{ padding: 50px !important; } p{ cursor: pointer; } </style> </head> <!--方式一:body中加入程式碼--> <body oncopy="aa();return false;"> <div style="width: 30%;margin: 0 auto;text-align: center;"> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> <p>內容內容內容內容內容內容內容內容內容內容內容</p> </div> <script type="text/javascript"> function aa(){ layer.msg('禁止複製!', { time: 2000, //2s後自動關閉 area: ['300px', '150px']//寬高 }); }; // 方式二:js中加入這兩行程式碼,使右鍵和複製失效. // document.oncontextmenu=new Function("event.returnValue=false"); // document.onselectstart=new Function("event.returnValue=false"); </script> </body> </html>
感謝分享https://blog.csdn.net/Bright2017/article/details/67639473