1

In a web app, I am capturing the escape key to exit out of an internal state. I also have support for the app to be embedded in an iframe with controls to make the app full-screen with the fullscreen API (requestFullscreen). Unfortunately, in chrome, the browser uses the escape key to exit out of fullscreen mode. This interferes with my escape key handler.

My first attempt was to try to call preventDefault() on the event. However, after some investigation, it appears that I am not getting the keydown event at all. I do however get other keydown events.

Are there any workarounds to capture the event and prevent the browser from exiting fullscreen mode?

EDIT:

here is what I have now:

$(document).keydown(function(e) {
    if( e.keyCode == 27) {
        alert('escape was pressed');
        //do some stuff
        e.preventDefault();
    }
});

The alert is never shown.

Thayne
  • 6,619
  • 2
  • 42
  • 67
  • pls include some code that you already tried, thanks! – benomatis Apr 14 '14 at 17:57
  • 1
    It appears you might want to research some more http://stackoverflow.com/questions/10706070/how-to-detect-when-a-page-exits-fullscreen – abc123 Apr 14 '14 at 18:10
  • your code works perfectly, so the issue might be coming from somewhere else... have you tried `return false`? here's some explanation on the difference: [http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false](http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false) – benomatis Apr 14 '14 at 18:19
  • @webeno, the problem is that my event handler isn't called, so returning false won't do me any good unless I can get my handler to be called. – Thayne Apr 14 '14 at 18:54
  • what do you mean by `I am not getting the keydown event at all. I do however get other keydown events`? – benomatis Apr 14 '14 at 18:57
  • I mean that if I press escape, I my keydown handler isn't called, but if I press another key, such as an arrow key, my keydown handler is called. – Thayne Apr 14 '14 at 18:58

0 Answers0