Tutorial :this.focus() does not work properly in Firefox


I am using an ExternalInterface call on activate from a flex application embedded within my html document. The call goes to a javascript function which does

function documentFocus() {    this.focus();  }  

Everything works like a charm, except that Firefox does not focus the document body 100%. It stops listening for onkeyup events (it still registers onkeydown).

Very odd behavior. Does anyone have a clue what is happening?

Try it here: http//www.willemdemmers.com/dplxr/

Steps to reproduce: Try arrow-buttons to see normal behavior (arrow images light up red on keydown and stop light on keydown) Click the flash at the bottom of the window to remove focus from the document body and invoke the function call. Try the arrow-buttons again and see the new behavior.

The key-events trigger from the arrow-keys (left and right).



This is actually a long standing Firefox bug that I wish would be fixed. I don't remember the Mozilla bug number off hand.


I think the issue is that flash is greedy on the keyboard when it's clicked and grabs it away from you.

You can see this in action on ie youtube. when you select a video you can use the up and down arrows to scroll up and down the page. But when you click into the flash area (the video) you can no longer do this. Since flash grabs the keyboard.


Check this out: http://code.google.com/p/custom-context-menu/

It's a project which disables flash's right click with javascript, and tells flash when it does so. Additionally, it works on a very very wide number of browsers.

not a 100% solution, but you should be able to adapt their JS code for your needs


You may try to focus hidden (or absolutely positioned away) input element, and then focusing document. Because inputs are almost native elements, it could help.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »