分享一段禁止右键菜单代码,禁止复制粘贴

 9年前     2,255  
分享一段禁止右键菜单代码,禁止复制粘贴

文章目录

    写了半天的代码,结果刚放到晚上就被人偷走代码,素不素很贱的赶脚,素不素

    一段代码完美解决,复制以下代码,添加到你的代码里,就可以禁止别人通过右键查看源文件偷走代码了

    <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>

    前往领取
    版权声明:字符猫 发表于 9年前,共 1326 字。
    转载请注明:分享一段禁止右键菜单代码,禁止复制粘贴 | 字符猫

    您可能感兴趣的