I'm making a game with HTML that uses a lot of the keys on the keyboard. I have event handlers set up for $(document).keypress
, but when I press the ' or / keys in Firefox, "quick find" appears, interrupting the game and shifting the focus away from the document.
How can I disable this? I don't have the problem in Chrome.
https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
Just call this in your key listener, when ' or / is pressed.
If you're using jquery, there is the method "preventDefault()" in the Event object. It's a good solution due to it's compatibility in all major browsers.
$('selector').bind('event', function (event){
event.preventDefault(); //this is what you want.
});
http://api.jquery.com/event.preventDefault/
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