有时,为了防止用户随意的获取页面内的内容,我们需要禁止用户选中和拷贝,下面介绍两种禁止的方法。  
javascript
可以在需要禁止的元素内监听选中和拷贝的事件,当用户如此操作时予以禁止。  
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 
 | document.oncontextmenu = function(){ return false; };
 
 document.onselectstart = function(){ return false; };
 
 document.oncopy = function(){ return false; };
 
 document.oncut = function(){ return false; };
 
 document.onpaste = function(){ return false; };
 
 document.onbeforeprint = function(){ return false; };
 
 | 
css
在支持use-select属性的浏览器中,设置user-select: none来禁止选中行为。
Opera12.5中支持私有的标签属性 unselectable=”on”来实现相同的行为  
| 12
 3
 4
 5
 6
 
 | * { -webkit-user-select: none;
 -moz-user-select: none;
 -ms-user-select: none;
 user-select: none;
 }
 
 | 
如何破解
如上所述,如果想要可以选中复制,可以在开发者工具F12中勾选禁止Javascript 并将想要复制的内容的element.style
改为user-select:none即可。当然,其实什么样的内容都可以在开发者工具的Element中复制得到。