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

Vignesh Pichamani
  • 7,120
  • 21
  • 68
  • 105
  • 2
    This is hopelessly impossible. Don't bother trying. – SLaks Apr 29 '13 at 13:59
  • 1
    That is some nice old code since Netscape has not been relevant in years. – epascarello Apr 29 '13 at 14:00
  • 4
    Please, _never_ try to stop users from doing what they are used to, it will only annoy them and make them stop using your site – epoch Apr 29 '13 at 14:03
  • 1
    you're definitely not the first one to try this either, there are a million people who already have working implementations available (like 10 seconds of googling informed me : ) http://www.arraystudio.com/as-workshop/disable-ctrl-n-and-other-ctrl-key-combinations-in-javascript.html – Timothy Groote Apr 29 '13 at 14:04
  • 1
    if you're looking for a great key-binding library, I suggest https://github.com/jeresig/jquery.hotkeys it's very nice ;) – Phil Apr 29 '13 at 14:08
  • 1
    You're supporting Netscape? Are you sending this website back to the 90s? – MMM Apr 29 '13 at 14:10
  • If its text you don't want to be able to select, may I suggest CSS. http://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting – CharliePrynn Apr 29 '13 at 14:11

2 Answers2

14

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.

Alex
  • 10,998
  • 6
  • 34
  • 52
What have you tried
  • 10,308
  • 4
  • 28
  • 45
5

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

<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.html Enjoy...!! :)

Kishan Patel
  • 1,308
  • 9
  • 23