0

I have a question thats semi-related to this question, except for instead of it being from the end-user perspective i need it from the content providers perspective.

I would be surprised if the mozilla foundation would have introduced this semi-intrusive feature with no way of it being disabled for selected content.

I have a web page that consists of nothing but a canvas element which is drawn to via javascript creating a game for the user to play. When a user uses the control keys (W, A, S & D) FireFox sees the user is not in some form of input box and decides they must be wanting to search for something of the page (opening the ctrl+f search box), forcing the user to lose focus on the game and their following key-presses to go unregistered. This will pose a problem for non-technical users who do not know where the setting to turn this off is, and in turn they will probably blame it on the content itself rather than it being the browser. Other than creating a input off the page that the user is force-focused to, is there a way of disabling this while FireFox users are visiting my page?

Community
  • 1
  • 1
James T
  • 1,155
  • 4
  • 17
  • 39

1 Answers1

1

After your event is handled just terminate it.

Example:

function handleDirectionalKeys(ev) {

  // .. Your WASD code

  ev.preventDefault();
  ev.stopPropagation(); // May not be needed, test it yourself

  return false;
}

Optionally you can cancel the event when it reaches the top level of the DOM hierachy:

$(window).keypress(function(e)
{
    // At this point you need to make sure that the key press
    // was already handled by your code
    e.preventDefault();
}
cvsguimaraes
  • 12,910
  • 9
  • 49
  • 73