1

How would be the code to set keyboard focus for swf on other browsers (not IE).

I know that for IE is just

document.getElementById('movieID').focus();

How would be for other browsers?

josh3736
  • 139,160
  • 33
  • 216
  • 263
Marcelo Noronha
  • 807
  • 2
  • 12
  • 26
  • your code is fine, please make further investigations to your code and search more thoroughly on the forum before posting such questions. anyway check out [this thread](http://stackoverflow.com/questions/4183325/focus-an-element-created-on-the-fly), a possible duplicate. – Eliran Malka Mar 21 '12 at 19:21
  • I think that only works for IE. Doesn´t work for Chrome. – Marcelo Noronha Mar 22 '12 at 00:53
  • That thread may give focus to flash but doesn´t gives keyboard focus to flash. – Marcelo Noronha Mar 22 '12 at 01:04

1 Answers1

2

The only HTML elements that natively support focus are links (<a>) and form elements, such a <input>. To make an HTML element focusable via javascript, you need to set the element's tabIndex.

(Jonathan Snook wrote a nice simple overview a few years back. Mozilla provides a good overview of the topic, and the W3C discusses keyboard focus in relation to ARIA.)

Once the Flash SWF is embedded, you can focus the new <object> element like so:

var flashvars = {};
var params = {};
var attributes = {};
var callbackFn = function(e){
   if(e.success){
      e.ref.tabIndex = "-1";
      e.ref.focus();
   }
};

swfobject.embedSWF("myfile.swf", "myflashelement", "550", "400", "9.0.0", "expressInstall.swf", flashvars, params, attributes, callbackFn);

Keyboard focus is discussed in depth in this SWFObject support thread if you'd like more information.

pipwerks
  • 4,440
  • 1
  • 20
  • 24