如何使用 javascript 禁用 ctrl + a?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16280582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 04:02:18  来源:igfitidea点击:

How can i disable the ctrl + a using javascript?

javascripthtmlwordpress

提问by Vignesh Pichamani

<script type="text/javascript">

function mischandler(){
return false;
}

function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
var isCtrl = false;
    document.onkeyup=function(e)
    {
    if(e.which == 17)
    isCtrl=false;
    }

    document.onkeydown=function(e)
    {
    if(e.which == 17)
    isCtrl=true;
    if((e.which == 85) || (e.which == 67) && isCtrl == true)
    {
    // alert(‘Keyboard shortcuts are cool!');
    return false;
    }
    }

</script>

Hi all , I using the code to disable the right click and also the ctrl+cand ctrl+uhow to disable the ctrlain the following code. Any help would be great.

大家好,我使用代码禁用右键单击以及ctrl+cctrl+u如何ctrla在以下代码中禁用。任何帮助都会很棒。

Thanks, vicky

谢谢,维琪

回答by What have you tried

You shouldn't try to do this, let me tell you why. I'm assuming you want to disable ctrl+ cbecause you don't want the user to be able to copy content from your site, well have you thought about the fact that there are a dozen of other ways to copy your content?

你不应该尝试这样做,让我告诉你为什么。我假设您想禁用ctrl+c因为您不希望用户能够从您的站点复制内容,那么您是否考虑过有很多其他方法可以复制您的内容?

  1. Download html file and copy in their favorite text editor
  2. Inspect element and copy content from there
  3. Use mouse to right click -> copy
  1. 下载 html 文件并复制到他们最喜欢的文本编辑器中
  2. 检查元素并从那里复制内容
  3. 使用鼠标右键单击 -> 复制

And for my good friend @glenatron:

对于我的好朋友@glenatron

  1. Network sniffer like Fiddler between the browser and the network card
  2. Screenshots, Taking a photograph of the monitor
  1. 浏览器和网卡之间类似Fiddler的网络嗅探器
  2. 屏幕截图,拍摄显示器照片

... The list goes on and on.

......这个名单不胜枚举。

Also, trying to stop users from normalfunctionality will only bother and annoy them; most likely causing them to leave your site and never return.

此外,试图阻止用户使用正常功能只会让他们感到烦恼和烦恼;最有可能导致他们离开您的网站,再也不会回来

回答by Kishan Patel

FInd the below code for detect ctrl + a,ctrl + A,ctrl + c,ctrl + C, ctrl + u,ctrl + U with your code editing.

通过您的代码编辑找到以下用于检测 ctrl + a,ctrl + A,ctrl + c,ctrl + C, ctrl + u,ctrl + U 的代码。

<script type="text/javascript">
var isNS = (navigator.appName == "Netscape") ? 1 : 0;

if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);

function mischandler(){
return false;
}

function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
var isCtrl = false;
document.onkeyup=function(e)
{
if(e.which == 17)
isCtrl=false;
}

document.onkeydown=function(e)
{
if(e.which == 17)
isCtrl=true;
if(((e.which == 85) || (e.which == 117) || (e.which == 65) || (e.which == 97) || (e.which == 67) || (e.which == 99)) && isCtrl == true)
{
// alert(‘Keyboard shortcuts are cool!');
return false;
}
}

you can get value for key from below link

您可以从下面的链接中获取密钥的价值

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000520.htmlEnjoy...!! :)

http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000520.html享受...!!:)