如何禁用复制粘贴(浏览器) [英] How to Disable Copy Paste (Browser)

查看:273
本文介绍了如何禁用复制粘贴(浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • 忽略右键点击

  • 忽略 ctrl + C ctrl + A

$ b

这是我的代码:

  function noMenu(){
return false;
}
函数disableCopyPaste(elm){
//禁用剪切/复制/粘贴按键事件
elm.onkeydown = interceptKeys
//禁用右键单击事件
elm.oncontextmenu = function(){
return false
}
}
函数interceptKeys(evt){
evt = evt || window.event // IE支持
var c = evt.keyCode
var ctrlDown = evt.ctrlKey || evt.metaKey // Mac支持
//检查Alt + Gr(http://en.wikipedia .org / wiki / AltGr_key)
if(ctrlDown& evt.altKey)return true
//检查ctrl + c,v和x
else if(ctrlDown&& amp; ; c == 67)return false // c
else if(ctrlDown& c == 86)return false // v
else if(ctrlDown&& c == 88)返回false // x
//否则允许
返回true
}

这是我的HTML:

 < body class =node88oncontextmenu =return noMenu(); onkeydown =return disableCopyPaste();> 

noMenu()函数正在工作,但 disableCopyPaste()不起作用。

解决方案

你可以尝试阻止一些向量(比如黑客让右击更难,拦截 ctrl + c ,这使得难以选择文本)...但他们只会做一些工作,并且不可能阻止所有向量(编辑 - >复制?查看源代码? wget 等等...)。

如果你试图保护你的内容不受技术用户的影响,这些方法可能没关系......但正如这里的评论所表明的,他们会挫败更多的技术用户。



如果您的敏感内容必须得到保护,您可能需要考虑将其嵌入到Flash Blob或DRM'd PDF中。这些仍然可以进行逆向工程,但是它会需要一个更加智能的攻击者。


I am trying 2 alternatives:

  • Ignore right-click
  • Ignore ctrl + C, ctrl + A

This is my code:

function noMenu() {
  return false;
}
function disableCopyPaste(elm) {
  // Disable cut/copy/paste key events
  elm.onkeydown = interceptKeys
  // Disable right click events
  elm.oncontextmenu = function() {
    return false
  }
}
function interceptKeys(evt) {
  evt = evt||window.event // IE support
  var c = evt.keyCode
  var ctrlDown = evt.ctrlKey||evt.metaKey // Mac support
  // Check for Alt+Gr (http://en.wikipedia.org/wiki/AltGr_key)
  if (ctrlDown && evt.altKey) return true
  // Check for ctrl+c, v and x
  else if (ctrlDown && c==67) return false // c
  else if (ctrlDown && c==86) return false // v
  else if (ctrlDown && c==88) return false // x
  // Otherwise allow
  return true
}

And this is my HTML:

<body class="node88" oncontextmenu="return noMenu();" onkeydown="return disableCopyPaste();">

The noMenu() function is working, but disableCopyPaste() doesn't work.

解决方案

You can't.

You can sort of try to block some vectors (like hacks to make right clicking more difficult, intercepting ctrl+c, making it difficult to select text)… But they will only sort of work, and it's impossible to block all vectors (edit -> copy? view source? wget? etc…).

If you are trying to protect your content from less technical users, these methods might be okay… But as the comments here suggest, they will frustrate more technical users.

If you have sensitive content that must be protected, you might want to consider embedding it in a Flash blob or a DRM'd PDF. These are still possible to reverse engineer, but it will take a slightly more intelligent attacker.

这篇关于如何禁用复制粘贴(浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆