zoukankan      html  css  js  c++  java
  • CSS -- 禁止用户选择

    CSS -- 禁止用户选择

    网站会有一些简单的保密需求,不想让用户复制文字,或者轮播图到头了,左右箭头还在点点点,会有蓝色的背景,使用下面的css就可以解决这种问题。

    CSS

    /* 禁止长按保存图片 */
    img {
      pointer-events:none;
    }
    /* 禁止复制文本 */
    *:not(input,textarea){
      -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 */
    }
    .select-none {
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none
    }
    .select-text {
      -webkit-user-select: text;
      -moz-user-select: text;
      -ms-user-select: text;
      user-select: text
    }
    .select-all {
      -webkit-user-select: all;
      -moz-user-select: all;
      -ms-user-select: all;
      user-select: all
    }
    .select-auto {
      -webkit-user-select: auto;
      -moz-user-select: auto;
      -ms-user-select: auto;
      user-select: auto
    }
    

    js(兼容IE6-9)

    document.body.onselectstart=document.body.ondrag=function(){
      return false;
    }
    document.addEventListener('contextmenu', function(e){
      e.preventDefault(); // 阻止默认右键菜单行为
    })
    document.addEventListener('selectstart', function(e){
      e.preventDefault(); 
    })
    
  • 相关阅读:
    终于开通了
    <input>表单元素readonly时光标仍然可见
    关于字体
    SSI架构中get***方法潜在调用
    为uploads文件夹瘦身
    在JSP里使用CKEditor和CKFinder
    centos5.5上搭建svn服务器
    多文件上传
    属性化ATL,DCOM,SIM,IID
    BSTR转换成char*
  • 原文地址:https://www.cnblogs.com/lisaShare/p/14393899.html
Copyright © 2011-2022 走看看