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?
In plain JavaScript, you can use the EventTarget. addEventListener() method to listen for keyup event. When it occurs, check the keyCode 's value to see if an Enter key is pressed.
To capture ctrl+z key combination in JavaScript, we can listen to the keydown event. document. addEventListener("keydown", (event) => { if (event. ctrlKey && event.
The keydown event occurs when a keyboard key is pressed down. The keydown() method triggers the keydown event, or attaches a function to run when a keydown event occurs. Tip: Use the event. which property to return which keyboard key was pressed.
You can override by capturing the event.
jQuery(document).bind("keyup keydown", function(e){ if(e.ctrlKey && e.keyCode == 80){ return false; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With