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?
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?
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.