views:

36

answers:

1

I am using a WebBrowser object to render text which is presented in a table format. This WebBrowser is embedded within an Eclipse plugin project. In order to comply the accessibility requirement, I need to make each entry in the WebBrower to have focus when using the up / down arrow keys to navigate through the entries so the screen reader can read out the text.

I can detect the up/down arrow keys through the java code, but I don't see the focus to be set on the entry. document.getElementById("+newPos+").focus();

I think this is because only button / form / text field can have focus within HTML.

Is there a way for the element to have focus? Or is there a way for the WebBrowser object to spell out the associated text in the entry when the up / down arrow keys are pressed?

Thanks a lot.

A: 

I had problems setting a focus on a div without having a height associated with it, although I did not put any listeners on it to check.

document.getElementById(newPos).focus();

However, without altering the newPos code to that, it errored.

With heights set, and using that alteration it allowed me to switch focus between two divs.

<body onload="var test = 'test2'; document.getElementById(test).focus()">
<div id="test"> 
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
</div>

<div id="test2" style="height: 50px; overflow: auto"> 
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
    The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.<br />
</div>

Change test from 'test2' to test to see the difference. In the second example it focuses, and I can keypress and it will move up and down. I think it's something to do with the scrolling that causes it.

Hope that is of some help.

corrodedmonkee
The <DIV> element I have here is a paragraph of text. Can I set focus on such <DIV> element?Could you provide some sample code in terms of how to set the height you referred to here?Thanks a lot
Java Doe
Updated with example. I don't know if that is a decent solution enough solution.
corrodedmonkee

related questions