其他分享
首页 > 其他分享> > js-禁止右键菜单代码、禁止复制粘贴代码

js-禁止右键菜单代码、禁止复制粘贴代码

作者:互联网

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

标签:禁止,false,text,代码,window,右键,tagName,return,event
来源: https://www.cnblogs.com/melodyjerry/p/13940749.html