When a web page is loaded, screen readers (like the one that comes with OS X, or JAWS on Windows) will read the content of the whole page. But say your page is dynamic, and as users performing an action, new content gets added to the page. For the sake of simplicity, say you display a message somewhere in a <span>
. How can you get the screen reader to read that new message?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
The WAI-ARIA specification defines several ways by which screen readers can "watch" a DOM element. The best supported method is the
aria-live
attribute. It has modesoff
,polite
,assertive
andrude
. The higher the level of assertiveness, the more likely it is to interrupt what is currently being spoken by the screen reader.The following has been tested with NVDA under Firefox 3 and Firefox 4.0b9:
The same thing can be accomplished with WAI-ARIA roles
role="status"
androle="alert"
. I have had reports of incompatibility, but have not been able to reproduce them.Here is an adapted real world example -- this up-level markup has already been converted from an unordered list with links into a select menu via JS. The real code is a lot more complex and obviously could not be included in its entirety, so remember this will have to be rethought for production use. For the select menu to be made keyboard accessible, we registered the keypress & onchange events and fired the AJAX call when users tabbed off of the list (beware of browser differences in timing of the onchange event). This was a serious PITA to make accessible, but it IS possible.