ARIA-屏幕阅读器无法读取的实时Firefox

人气:442 发布:2022-10-16 标签: html javascript firefox accessibility aria-live

问题描述

我遇到一个问题,屏幕阅读器无法读取Firefox的aria-live部分中更改的文本。

这是一个简单的页面示例,在Chrome中,屏幕阅读器读取传入的更改,而在Firefox中不读取更改:

<div aria-live="assertive" id="moo">

</div>
<script>
  let i = 0;
  setInterval(() => {
    document.getElementById('moo').innerText = 'moo' + i++
  }, 2000)
</script>

我做错了什么吗?除了人们在Firefox上使用的aria-live之外,还有没有其他方式在更改到来时宣布?

我在Mac-Firefox-VoiceOver上测试过(它可以在Mac-Chrome-VoiceOver上运行)

推荐答案

当前火狐版本:83.064位 Firefox夜间版本:85.0a1(2020-11-29)(64位) 在最新的夜间版中,aria-live on Firefox+VoiceOver的组合已修复!万岁!

引用: Firefox/Voiceover: aria-live regions not being announced

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Aria-live Demo</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <style>
    body {
  margin: 1em;
}

button {
  margin-top: 1em;
  display: block;
}
  </style>
</head>
<body>
  <h1>Aria-live Demo</h1>
  <p>Testing <code>aria-live</code><br><button>Add Content</button><button id="add-more" >Add more content</button></p>

  <!-- add aria-live="polite" -->
  <div class="target" aria-live="polite" ></div>
 
  <script type="text/html" id="test-content">
    <h2>Custom Content</h2>
    <p>Hello there! I am content that is going to be plunked into a container via javascript</p>
  </script>

  <input placeholder="messgae somebody"/>
<script>
$("button").on("click", function(){
  $(".target").html($("#test-content").html());
});

$("#add-more").on("click", function(){
  $(".target").append("<p>Hello World</p>");
});

$(document).on("keydown", function(e){
  // press space to add content
    if(e.keyCode === 32) {
        $(".target").append("<p>Hello World</p>");
    }
});

</script>
</body>
</html>

608