有關(guān)不允許頁面選擇復(fù)制的幾種方法
1 JS方法
- 以下方法我發(fā)現(xiàn)把左鍵選擇 右鍵都控制了,剛一點擊,就執(zhí)行這個函數(shù)了
$(document.body).bind("selectstart", function(){
return false;
});
2 css方法
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently not supported by any browser */
}
-在 IE < 10 和Opera < 15中我們需要在需要禁止選中的元素上面添加一個屬性
unselectable="on"洽蛀,否則可能不會生效哦~不過現(xiàn)代瀏覽器如果不是非得兼容一些老的瀏覽器也可以不加田藐。