简体   繁体   中英

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?

You can override by capturing the event.

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

还有一个很棒的图书馆是Mousetrap

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM