+ -

html怎么禁止复制粘贴

时间:2021-05-22

来源:互联网

在手机上看
手机扫描阅读

今天PHP爱好者为您带来在html中,可以利用touch-callout和user-select属性来属性禁止复制粘贴功能,只需要设置“user-select:none;-webkit-touch-callout:none;”样式即可。希望对大家有所帮助。

html怎么禁止复制粘贴

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

小伙伴们在开发的时候偶尔会遇到这样的需求,客户要求文章页禁止复制和粘贴,实现这个功能代码如下 (可同时实现PC端和手机端):

*{
-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 上会有问题的,这个时候你会发现input 框无法正在输入了内容了;造成这个原因就是 -webkit-user-select:none; 这个属性造成的。

解决这个方法 就是 在css 文件中同时设置一下input 的属性,如下所示:

input {
-webkit-user-select:auto; /*webkit浏览器*/
}

以上就是html怎么禁止复制粘贴的详细内容,更多请关注php爱好者其它相关文章!