码迷,mamicode.com
首页 > 其他好文 > 详细

防止你的代码被扒

时间:2017-10-27 15:49:03      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:粘贴   blog   window   屏蔽   sele   别人   try   ase   ``   

```
//若是你不想别人扒掉你的模板,可以把这段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; 

    } 

}
```

 

防止你的代码被扒

标签:粘贴   blog   window   屏蔽   sele   别人   try   ase   ``   

原文地址:http://www.cnblogs.com/yidaixiaohui/p/7742727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!