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

会有一股神秘感。 提交于 2019-12-29 04:30:34

问题


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?


回答1:


You can override by capturing the event.

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



回答2:


Also a great library is Mousetrap




回答3:


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



来源:https://stackoverflow.com/questions/12517819/how-to-listen-for-ctrl-p-key-press-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!