当前位置 : 主页 > 网络编程 > JavaScript >

防别人反扒自己东西的代码片段

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt //若是你不想别人扒掉你的模板,可以把这段js代码加到你网页上,即可屏蔽鼠标右键菜单、复制粘贴、选中等//屏蔽右键菜单 document.oncontextmenu = function(event) { if (window.event)
gistfile1.txt
//若是你不想别人扒掉你的模板,可以把这段js代码加到你网页上,即可屏蔽鼠标右键菜单、复制粘贴、选中等

//屏蔽右键菜单 
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; 

    } 

}
网友评论