zoukankan      html  css  js  c++  java
  • js屏蔽浏览器右键菜单,粘贴,复制,剪切,选中(转)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js屏蔽浏览器右键菜单,粘贴,复制,剪切,选中</title>
    <meta name="description" content="js代码制作屏蔽浏览器右键菜单,屏蔽浏览器粘贴,屏蔽浏览器复制,屏蔽浏览器剪切,屏蔽浏览器选中,不会屏蔽搜索引擎蜘蛛抓取页面,不影响seo优化。可以设置网页内容代码不被用户随意下载等。" />
    </head>
    
    <body>
    
    <script type="text/javascript">
    //屏蔽右键菜单
    document.oncontextmenu = function (event){
        if(window.event){
            event = window.event;
        }try{
            var the = event.srcElement;
            if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
                return false;
            }
            return true;
        }catch (e){
            return false; 
        } 
    }
    
    //屏蔽粘贴
    document.onpaste = function (event){
        if(window.event){
            event = window.event;
        }try{
            var the = event.srcElement;
            if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
                return false;
            }
            return true;
        }catch (e){
            return false;
        }
    }
    
    //屏蔽复制
    document.oncopy = function (event){
        if(window.event){
            event = window.event;
        }try{
            var the = event.srcElement;
            if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
                return false;
            }
            return true;
        }catch (e){
            return false;
        }
    }
    
    //屏蔽剪切
    document.oncut = function (event){
        if(window.event){
            event = window.event;
        }try{
            var the = event.srcElement;
            if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
                return false;
            }
            return true;
        }catch (e){
            return false;
        }
    }
    
    //屏蔽选中
    document.onselectstart = function (event){
        if(window.event){
            event = window.event;
        }try{
            var the = event.srcElement;
            if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
                return false;
            }
            return true;
        } catch (e) {
            return false;
        }
    }
    </script>
    
    
    <div style="600px;margin:40px auto;text-align:center;border:solid 1px #FFCA52;background:#FFFDD2;height:28px;line-height:28px;font-size:14px;padding:5px 10px;color:#ff0000;font-weight:800;">单页禁用右键菜单、粘贴、复制、剪切、选中操作</div>
    test
    </body>
    </html>
  • 相关阅读:
    Access 通用访问类 OleDbHelper
    让Visual Studio 也支持JS代码折叠 [ Visual Studio | #region | #endregion ]
    提高网站性能的方法
    php 正则表达式整理 归纳 重点
    C++数据结构知识点
    algorithm算法设计,数据结构基本概念之我的归纳 by whb_咸菜圣斗士啊斌斌斌斌
    浏览器兼容性问题及常见的解决方法
    js抽象方法的使用
    js制作图片轮换切换
    C语言排序算法总结
  • 原文地址:https://www.cnblogs.com/liusijia/p/5728754.html
Copyright © 2011-2022 走看看