简体   繁体   English

如何在屏幕阅读器中隐藏链接?

[英]How to hide a link from a screen-reader?

I have a link which I want to show to visitors with vision, but hide from visitors using screen-reader ATs.我有一个链接,我想向有视力的访问者展示,但使用屏幕阅读器 AT 向访问者隐藏。 (This is not ideal of course). (这当然不是理想的)。

This is the reverse of the usual problem (with known solution) of hiding content from vision visitors (eg a "skip to content" link)这与向视觉访问者隐藏内容的常见问题(具有已知解决方案)相反(例如“跳转到内容”链接)

An example:一个例子:

一个带有 lede 文本的框,以及一个“阅读更多”的链接

Clicking the "read more" link expands the text inline.单击“阅读更多”链接可展开内联文本。

同一个框,这次是所有文本

and conversely, clicking the "read less" link collapses it again.相反,单击“少读”链接会再次折叠它。

This collapsed/expanding text functionality is only of benefit to visitors with vision, whose field of view would take in the extra text before they get to it (and in this example displaces the next FAQ, pushing it off screen).这种折叠/展开文本功能仅对有视力的访问者有益,他们的视野会在他们到达之前接收额外的文本(在本例中取代下一个常见问题解答,将其推离屏幕)。

A visitor with a screen-reader should instead be presented with the full text as they can choose to skip ahead to the next block, and they shouldn't encounter a spurious "read more" link which (a) doesn't link to a page, and (b) simply gives them what they were about to hear from their screen reader anyway.带有屏幕阅读器的访问者应该看到全文,因为他们可以选择跳到下一个块,并且他们不应该遇到虚假的“阅读更多”链接(a)不链接到页面,并且 (b) 只是简单地向他们提供他们将要从屏幕阅读器中听到的内容。

How would this be done in HTML5?这将如何在 HTML5 中完成?

以这种方式对内容使用aria-hidden

<p aria-hidden="true">Screen readers will not read this!</p>

You can try to put the link in a pseudo element.您可以尝试将链接放在伪元素中。 That's brings another issue: you can't click on a pseudo element because is not part of the DOM, but can fake it with pointer-events .这带来了另一个问题:你不能点击伪元素,因为它不是 DOM 的一部分,但可以用pointer-events伪造它。

 $("p").click(function () { $("span").toggleClass('on'); });
 span {display:none; color:red} p {pointer-events:none} p:after {content:"Read more"; color:blue; text-decoration:underline; display: block;pointer-events:all} span.on {display:block}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at erat orci. Praesent non pulvinar nisl, at ultrices lorem. Sed semper ultricies eros, eu aliquet ipsum vehicula nec. Nullam orci justo, dapibus eget elit ac, tincidunt mollis urna. Ut sed felis lobortis, blandit urna non, fermentum arcu. Suspendisse fermentum elit ante. Nulla tincidunt elit vel elementum eleifend. Fusce sed nisi vulputate, aliquam urna congue, egestas arcu.<span> Praesent dignissim, risus in elementum eleifend, velit elit accumsan diam, sit amet vestibulum purus urna quis dui. Proin ut venenatis orci, sit amet ullamcorper tellus. Morbi lorem purus, ornare non convallis nec, venenatis cursus urna. Maecenas cursus, leo vel tincidunt viverra, leo nibh placerat sem, ut molestie tellus ex et nulla. Vivamus eget magna libero.</span></p>

I use display:none as an example, of course I assume you have your own method to hide the text but no for JAWS or other screen readers.我使用display:none作为示例,当然我假设您有自己的方法来隐藏文本,但对于 JAWS 或其他屏幕阅读器则没有。

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

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