views:

128

answers:

1

I have a Java applet with several focusable elements that is embedded in a web page.

Is it possible to make the elements in the applet part of the logical tab order of the rest of the page?

To clarify: I would like to use Tab to move from an element outside the applet to the first element of the applet and then use Shift+Tab to move back to the element outside the applet. Similarly I would like to use Tab to move from the last element of the applet to the next element of the web-page and use Shift+Tab to move back.

+2  A: 

You can define the tab order within your page by attaching tabindex attributes to your elements, including your applet’s object element. You can define the tab order within your applet by extending the FocusTraversalPolicy class.

Let’s say you have three page controls — A, B, and C — the second of which — B — is your applet, and three applet controls — X, Y, and Z. If you make controls A, B, and C tabindex 1, 2, and 3 and X, Y, and Z first through third in the traversal cycle, your effective tab order will be: A, X, Y, Z, C.

byoogle
tabIndex on applet tags does not behaves consistently across browsers. On IE7 lets me tab into the applet, but I cannot tab back out. Firefox lets me tab into the applet, but does not give focus to the applet's controls. Chrome ignores the applet in the taborder despite the tabIndex. I do not see any way of indicating in the FocusTraversalPolicy that I want (to use your example) to move focus outside the applet after Z. Am I overlooking something?
Rasmus Faber
@Rasmus Faber: AFAIK, you're not missing anything. Applets simply aren't designed to be a part of the web page, but rather a mini application (hence the name) embedded on the page.
Brian S
I disagree that applets aren’t designed to be part of the page. According to the HTML spec, “tabindex” ought to be supported by “object” tags <http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex>. So the approach I described ought to work unless the browsers are behaving badly. Unfortunately, it appears they are — I just tried the whole shebang out and reproduced the inconsistent behavior across browsers. In which case Rasmus, I’m afraid you’re, as the French might say, “shit out of luck”.
byoogle