user-select : 保护版权内容的简单方案
2016-06-06 10:06
218 查看
有的适合我们需要保护我们页面的内容,为了版权或者安全等原因,这个适合我们可以使用 user-select 这个CSS属性,简单易用。
嗯,这个属性不麻烦,而且也不是 CSS 3 / CSS 4 的新属性,这里简单归纳一下:
不过,这个属性还并没有被各浏览器以标准的行为来实现,所以使用的适合还是要加上各种前缀:
注意: IE 9 才开始支持,IE 8 及更早期的版本不支持
当然,js方案可以兼容到低版本 IE 浏览器。
嗯,这个属性不麻烦,而且也不是 CSS 3 / CSS 4 的新属性,这里简单归纳一下:
.control-select { user-select: none; /* 禁止选择 */ user-select: auto; /* 浏览器来决定是否允许选择 */ user-select: all; /* 可以选择任何内容 */ user-select: text; /* 只能选择文本 */ user-select: contain; /* 选择绑定的元素以内的内容 */ }
不过,这个属性还并没有被各浏览器以标准的行为来实现,所以使用的适合还是要加上各种前缀:
.no-select { -moz-user-select: none; -ms-user-select: none; -webkit-user-select: none; }
注意: IE 9 才开始支持,IE 8 及更早期的版本不支持
Javascript方案
当然也可以用 javascript 来实现类似的行为://禁用选择 function disableSelection() { document.onselectstart = function() {return false;} // IE 浏览器 document.onmousedown = function() {return false;} // 其它浏览器 } //启用选择 function enableSelection() { document.onselectstart = null; // IE 浏览器 document.onmousedown = null; // 其它浏览器 }
当然,js方案可以兼容到低版本 IE 浏览器。
相关文章推荐
- 剑指offer(6)-旋转数组的最小数字
- 音乐播放器
- tomcat端口配置
- JavaFX Dialogs (官方支持)
- AFNetworking 同时向服务端传送参数+图片
- iOS中 @synthesize 和 @dynamic
- 九章算术卷第八 方程
- NSMutableArray在alloc init之后再调用addobject还是会崩溃的可能原因有哪些? 出现错误:[__NSArrayI addObject:]: unrecognized sel
- 转储控制文件
- 三星note4怎样恢复手机删除的照片
- android之BadTokenException异常
- 一直使用的图片压缩的代码,做个笔记
- EasyUI combobox 多选及回显赋值
- .net后台webclient用post方式发送文件和数据
- EasyUI combobox 多选及回显赋值
- Linux 进程优先级查看及调整
- EasyUI combobox 多选及回显赋值
- jpg和rar格式转换
- 二分查找法分析
- 【Android基础知识】ContentProvider(一)