Mustapha Aoussar
Mustapha Aoussar

Reputation: 5923

How to disable CTRL + mouse Left Click?

I want to disable Ctrl + mouse Left Click event on links. I tried with keypress event but it doesn't work:

$('a').keypress(function (e){  
    if (e.ctrlKey && e.keyCode === 13) {
        return false;
    }
});

jsFiddle

Upvotes: 0

Views: 10661

Answers (2)

Peter Hoogstrate
Peter Hoogstrate

Reputation: 31

The full code is:

<script src="https://code.jquery.com/jquery-2.1.0.js"></script>

<script>

$(window).load(function(){

    // Disable CTRL Mouse Click    
    $('a').click(function (e){  
      if (e.ctrlKey) {
        return false;
      }
    })

    // Disable SHIFT Mouse Click    
    $('a').click(function (e){  
      if (e.shiftKey) {
        return false;
      }
    })

})

</script>

Upvotes: 3

Guffa
Guffa

Reputation: 700252

The code that you have disables Ctrl+enter. To disable Ctrl+click, you would use the click event:

$('a').click(function (e){  
    if (e.ctrlKey) {
        return false;
    }
});

Demo: http://jsfiddle.net/WYxUE/45/

Note: Actually disabling ctrl+click would normally not be a good idea, and not very effective. In windows it's used to open the page in a new tab, and if that is disabled you can just use shift+click to open it in a new window instead, or right click and choose Open link in new tab.

Upvotes: 12

Related Questions