Marcer
Marcer

Reputation: 849

How to listen for Ctrl-P key press in JavaScript?

I want to disable print for some webpages. How to wireup cross browser hotkeys (Cntrl + P) to a javascript that will be fired whenever hotkeys are pressed?

Upvotes: 32

Views: 38377

Answers (3)

Anoop
Anoop

Reputation: 23208

You can override by capturing the event.

jQuery(document).bind("keyup keydown", function(e){
    if(e.ctrlKey && e.keyCode == 80){
        return false;
    }
});

Upvotes: 56

Charlie G
Charlie G

Reputation: 824

Also a great library is Mousetrap

Upvotes: 4

nana
nana

Reputation: 4481

Try Keyboard Shortcuts Library.

Instead of just copy pasting it let's havea look at the source and understand how it works.

You can see the source here

Upvotes: 2

Related Questions