最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览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

<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

Share Improve this question edited May 6, 2013 at 11:05 Vignesh Pichamani asked Apr 29, 2013 at 13:58 Vignesh PichamaniVignesh Pichamani 8,07022 gold badges80 silver badges117 bronze badges 7
  • 2 This is hopelessly impossible. Don't bother trying. – SLaks Commented Apr 29, 2013 at 13:59
  • 1 That is some nice old code since Netscape has not been relevant in years. – epascarello Commented Apr 29, 2013 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 Commented Apr 29, 2013 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 : ) arraystudio.com/as-workshop/… – Timothy Groote Commented Apr 29, 2013 at 14:04
  • 1 if you're looking for a great key-binding library, I suggest github.com/jeresig/jquery.hotkeys it's very nice ;) – Phil Commented Apr 29, 2013 at 14:08
 |  Show 2 more comments

3 Answers 3

Reset to default 13

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.

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

How can i disable the ctrl + a

I had the same question but for a different reason,

I had multiple textPath elements in my DOM and because of some weird bug, whenever I pressed ctrl + a they all change position, to fix that I added:

body{
   ...

   user-select:none    
}

I guess this also "technically" disables Ctrl + a

发布评论

评论列表(0)

  1. 暂无评论