Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the slash and apostrophe keys from popping up quick find in Firefox with html/javascript?

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.

like image 759
Nick Avatar asked Oct 25 '11 18:10

Nick


2 Answers

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
Just call this in your key listener, when ' or / is pressed.

like image 104
Fisher Avatar answered Nov 07 '22 19:11

Fisher


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/

like image 37
szanata Avatar answered Nov 07 '22 19:11

szanata