Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable select all (ctrl+a) [duplicate]

I want to disable any image selecting in my website. I already use this code:

  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -o-user-select: none;
  user-select: none;

but still have a problem with CTRL+A. Is there any jQuery or Javascript code to disable CTRL+A and select all function?

EDIT : this is my website > http://narenjco.ir/ press ctrl+a in first page , i want to make sparks unselectable

like image 941
Mori uzx Avatar asked May 15 '13 09:05

Mori uzx


2 Answers

Edit: I now see that you've applied it to the images within the .unselectable class. In Chrome these images are unselectable, so the issue appears to be browser-specific. To overcome this problem in whichever browser you're using you'll need to use JavaScript.


It's all to do with the usage of your user-select:none. Currently, I can't see on your site where this has been applied, however applying it to the body tag does prevent Ctrl+A from selecting any content (in Chrome at least).

body {
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    user-select: none;
}
like image 87
James Donnelly Avatar answered Oct 20 '22 09:10

James Donnelly


Try this

$(function(){   
    $(document).keydown(function(objEvent) {        
        if (objEvent.ctrlKey) {          
            if (objEvent.keyCode == 65) {                         

                return false;
            }            
        }        
    });
});   
like image 4
Sudz Avatar answered Oct 20 '22 09:10

Sudz