现在有好多人为了省事直接复制他人的文章,从而损害到别人的利益,那么如何从技术上保护呢?
问: 前端开发css禁止选中文本如何禁止选中文字???
禁止选中的方法很简单,有两种方法:JS和CSS两种
直接干货
123456789 | if(document.all){ document.onselectstart= function(){return false;}; //for ie}else{ document.onmousedown= function(){return false;}; document.onmouseup= function(){return true;};}document.onselectstart = new Function('event.returnValue=false;'); //劫持开始选择事件和(或)鼠标按下、抬起事件。 |
---|
简单方法,可以直接在标签里添加
onselectstart="return false;
例子如下:
123 | <div onselectstart="return false"> adasdasdasdasdasdasdad </div> |
---|
user-select有两个值: