Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

html - How can i disable the ctrl + a using javascript?

<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+c and ctrl+u how to disable the ctrl a in the following code. Any help would be great.

Thanks, vicky

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You shouldn't try to do this, let me tell you why. I'm assuming you want to disable ctrl + c because 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?

  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

And for my good friend @glenatron:

  1. Network sniffer like Fiddler between the browser and the network card
  2. Screenshots, Taking a photograph of the monitor

... The list goes on and on.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...