直接在CSS 文件中添加下面的代码,就可以实现了在手机端禁止粘贴复制的功能:
*{
-webkit-touch-callout:none; /*系统默认菜单被禁用*/
-webkit-user-select:none; /*webkit浏览器*/
-khtml-user-select:none; /*早期浏览器*/
-moz-user-select:none;/*火狐*/
-ms-user-select:none; /*IE10*/
user-select:none;
}
注:当前只兼容IOS
在添加完这段代码后,在IOS 上会出现一个bug问题,此时的input 框和 textarea框都因失去了焦点而无法输入内容;而造成这个原因就是css的 -webkit-user-select:none; 这个属性造成的。
解决这个方法 就是 在css 文件中同时设置一下input和 textarea 的属性,如下所示:
input, textarea{
-webkit-user-select:auto; /*webkit浏览器*/
}
另兼容Android和ios的写法:
用a标签包起来,在a标签里面加一句代码 ontouchstart = "return false;" ,此方法建议只在小模块添加
以上为HTML+css的方法
js方法禁止右键及复制功能
document.οncοntextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
使用的时候建议将css及js方法都添加上,双重保险更加安全 ( ^-^)