美文网首页
禁止复制粘贴操作

禁止复制粘贴操作

作者: 程序员是粉色的 | 来源:发表于2022-01-18 10:34 被阅读0次
    //屏蔽右键菜单
    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>
    

    相关文章

      网友评论

          本文标题:禁止复制粘贴操作

          本文链接:https://www.haomeiwen.com/subject/tckkhrtx.html