最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - accessibility aria-live not working when loading a page - Stack Overflow

programmeradmin4浏览0评论

I am trying to get my screen reader to read the message whenever my page loads with a message. Below is the code that I have used. I could read the message when I hover on the text. But, for some reason I cannot get the screen reader to read my message on page load . Please suggest if there is something that I need to do.

<div class="bannerError">
    <div class="bannerError_image"></div>
    <span class="bannerError_text" aria-live="assertive">Please enter your name
    </span>
</div>

I am trying to get my screen reader to read the message whenever my page loads with a message. Below is the code that I have used. I could read the message when I hover on the text. But, for some reason I cannot get the screen reader to read my message on page load . Please suggest if there is something that I need to do.

<div class="bannerError">
    <div class="bannerError_image"></div>
    <span class="bannerError_text" aria-live="assertive">Please enter your name
    </span>
</div>
Share Improve this question edited Feb 23, 2018 at 16:46 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Feb 23, 2018 at 13:35 AravindAravind 792 gold badges2 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The live region container must be present in the HTML at the time of page load, however it should not contain any content initially.

Only after the page has loaded will the contents of the live region be monitored for updates. Adding content to the live region is typically acplished via JavaScript.

You may want to take a look at the WCAG page for aria-live usage: W3C - Using ARIA role=alert or Live Regions to Identify Errors

Also, Terril Thompson has a pretty good live region testing page that illustrates some of the different ways that aria-live can be implemented.

发布评论

评论列表(0)

  1. 暂无评论