小说网站禁止复制黏贴功能
作者:互联网
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <p>hello world</p> <input type="text"> <script> document.addEventListener("mousedown" , function( evt ){ var e = evt || event; // 判定事件源是否是input,如果不是input那么我们就阻止默认事件; var target = e.target || e.srcElement; if( target.nodeName !== "INPUT"){ e.preventDefault(); } })
//禁用鼠标右键 document.addEventListener("contextmenu" , function( evt ){ var e = evt || event; e.preventDefault(); }); document.addEventListener("keydown" , function( evt ){ var e = evt || event; var code = e.keyCode || e.which; //禁止F12 if( code === 123){ e.preventDefault(); } }) </script> </body> </html>
运用事件源监听
标签:function,禁止,document,复制,addEventListener,var,黏贴,evt,event 来源: https://www.cnblogs.com/wei-hang/p/14698237.html