简体   繁体   English

为屏幕阅读器设置文本并在屏幕阅读器中隐藏子项

[英]Set text for screen reader and hide children from screen readers

I have an iframe, inside which arbitrary content is served.我有一个 iframe,其中提供任意内容。 I want to ensure content within the iframe is not accessible to screen readers, and specify what screen readers should read out when the iframe is selected.我想确保屏幕阅读器无法访问 iframe 中的内容,并指定选择 iframe 时应读出的屏幕阅读器。

My expectation is when tabbing through different elements on the page, myDiv is selected as a single unit, and it reads out Unknown content .我的期望是在页面上的不同元素之间myDivmyDiv被选为一个单元,并读出Unknown content

I tried the following我尝试了以下

<div id="myDiv" title="Unknown content">
  <iframe id="myIframe" aria-hidden="true">
    {arbitraryContent}
  </html>
</div>

Problems I face with this are我面临的问题是

  1. Not all content within the iframe are being ignored.并非 iframe 中的所有内容都被忽略。 Perhaps that is because aria-hidden does not work with focusable child elements.也许这是因为aria-hidden不适用于可聚焦的子元素。
  2. Unknown text is not always being read, especially if the child elements are focusable. Unknown text并不总是被读取,尤其是在子元素可聚焦的情况下。
  3. I also tried setting tabIndex=-1 on the iframe.我还尝试在 iframe 上设置tabIndex=-1 This however causes all the elements (including myDiv ) to not be selectable by keyboard.然而,这会导致所有元素(包括myDiv )无法通过键盘选择。

What is the right approach to achieve what I am looking for?实现我正在寻找的目标的正确方法是什么?

If you prevent the screen reader from reading the entire iframe and if it still has focusable elements, yes, you have a fatal accessibility problem: you can focus something but the screen reader isn't allowed to tell what is focused.如果您阻止屏幕阅读器阅读整个 iframe 并且它仍然具有可聚焦元素,那么,是的,您有一个致命的可访问性问题:您可以聚焦某些东西,但不允许屏幕阅读器知道聚焦的是什么。 So what to do ?那么该怎么办 ? Should it say nothing, or go against what you have defined ?它应该什么都不说,还是违背你的定义?

Technically, it means that there shouldn't be any focusable element inside aria-hidden=true .从技术上讲,这意味着aria-hidden=true 中不应该有任何可聚焦的元素 You must ensure that it never happens.您必须确保它永远不会发生。

However, the good question you have to ask yourself is why do you want to completely hide what is in the iframe or in other words, explicitely make it totally unaccessible.但是,您必须问自己的一个好问题是,为什么要完全隐藏 iframe 中的内容,或者换句话说,明确地使其完全无法访问。

IF your fear is that contents out of your control could break the accessibility of your page, then如果您担心不受您控制的内容可能会破坏您页面的可访问性,那么

Administratively speaking, certifications based on WCAG complience know this problem and usually accept exceptions, ie don't take into account something you haven't control in.从管理上来说,基于 WCAG 合规性的认证知道这个问题并且通常接受例外情况,即不考虑您无法控制的事情。

Pratically speaking as a screen reader user, the badly accessible iframe will probably indeed give the impression that the whole accessibility of your site is bad in general, but it's still certainly better to have some partially accessible content rather than nothing at all.实际上,作为屏幕阅读器用户,可访问性差的 iframe 可能确实给人的印象是您网站的整体可访问性总体上很糟糕,但拥有一些部分可访问的内容肯定比什么都没有要好。 You'd better remove the aria-hidden=true.你最好删除 aria-hidden=true。 Even if you know that it isn't very accessible, leave a chance to access a little of it no matter what, instead of blocking it definitely.即使您知道它不是很容易访问,无论如何也要留出一点访问它的机会,而不是绝对阻止它。 Perhaps the accessibility of the content will improve over time.也许内容的可访问性会随着时间的推移而提高。

The exception to this is if the content of the iframe is objectionnable, decorative, or doesn't bring any real information in the context of your page.例外情况是 iframe 的内容令人反感、装饰性或在您的页面上下文中没有带来任何真实信息。 Typical examples include ads and various kinds of widgets (weather, clock, social network share, etc.) For those, go ahead, leave the aria-hidden=true and remove all focusable elements of the iframe.典型的例子包括广告和各种小部件(天气、时钟、社交网络共享等)。对于那些,继续,保留 aria-hidden=true 并删除 iframe 的所有可聚焦元素。 They are anyway just useless noise, without any regret if they are completely skipped.无论如何,它们只是无用的噪音,如果完全跳过它们,也不会后悔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM