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 modes off
, polite
,assertive
and rude
. 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:
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.4.2.min.js"></script>
</head>
<body>
<button onclick="$('#statusbar').html(new Date().toString())">Update</button>
<div id="statusbar" aria-live="assertive"></div>
</body>
The same thing can be accomplished with WAI-ARIA roles role="status"
and role="alert"
. I have had reports of incompatibility, but have not been able to reproduce them.
<div id="statusbar" role="status">...</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…