是否可以使用 javascript 来检测屏幕阅读器是否正在用户计算机上运行?
我想检测屏幕阅读器是否正在用户的计算机上运行,以避免声音与 html 中的音频标签发生冲突。如果是这样,请提供如何做到这一点的详细信息。
I want to detect whether a screen reader is running on a user's machine to avoid sound clashing with audio tag in html. If so, please provide details on how this could be done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使您可以检测到屏幕阅读器正在运行,您也不应该尝试执行任何特殊操作。即使您对一组屏幕阅读器用户来说是正确的,对另一组用户来说也可能是错误的。最好首先集中精力编写干净的 HTML5。
请注意,并非所有屏幕阅读器用户都使用文本转语音;许多使用盲文输出。此外,其他类型的辅助工具(例如内容突出显示和语音输入应用程序)使用与屏幕阅读器相同的技术和 API(例如 DOM、MSAA),因此任何“检测屏幕阅读器”的技术也可能会检测到这些 - 因此您不能假设这意味着用户完全失明且仅使用语音。
就目前情况而言,音频标签目前尚未普遍访问,不同的浏览器具有不同级别的辅助功能支持 - 请参阅 HTML5 辅助功能并向下滚动到音频以获取当前支持的更多详细信息。我见过一些页面在音频标签后添加基于 HTML5 的控件和 javascript,这样它们就可以提供自己的 UI,以确保键盘或屏幕阅读器用户可以根据需要播放/停止音频。 (最终,当浏览器迎头赶上时,就不需要这样做了。)
就一般可访问性而言,WCAG 2.0 (网页内容可访问性指南)建议任何自动播放超过 3 秒的音频都应该有一种可访问的方式来暂停或停止音频。 (我会更进一步,建议不要使用任何自动音频 - 使用选项卡式浏览时,通常无法确定音频来自哪个选项卡。)
You should probably not try to do anything special even if you could detect that a screenreader is running. Even if you get it right for one group of screenreader users, you may get it wrong for another group. It's best to concentrate on writing good clean HTML5 in the first place.
Note that not all screenreader users use text-to-speech; many use braille output. Additionally, other types of accessibility tools - such as content highlighters and voice input apps - use the same techniques and APIs (eg. DOM, MSAA) that screenreaders do, so any technique that "detects a screenreader" will likely detect these also - so you cannot assume that it means that the user is fully blind and using only speech.
As things currently stand, the audio tag is currently not universally accessible, different browsers have different levels of accessibility support - see HTML5 Accessibility and scroll down to audio for more details of current support. I've seen some pages that add HTML5-based controls plus javascript after the audio tag so they can provide their own UI to ensure that keyboard or screenreader users can play/stop the audio as needed. (Eventually, when browsers catch up, this should not be needed.)
As far as general accessibility goes, WCAG 2.0 (Web Content Accessibility Guidelines) recommends that any audio that plays automatically for more than 3 seconds should have an accessible means to pause or stop the audio. (I'd go even further and recommend against using any automatic audio - when using tabbed browsing, it's often impossible to determine which tab the audio is coming from.)
虽然这可能不是完全可靠的方法,但当用户浏览内容时,可以使用焦点事件通过 JavaScript 检测屏幕阅读器的进度。
隐藏的“跳过导航链接”(http://webaim.org/techniques/skipnav/)如果它具有焦点,这将是检测某人是否正在使用屏幕阅读器的一种方法。
即使它没有解决问题的音频部分。我只是想提供这个部分解决方案,因为我正在寻找自己检测屏幕阅读器的可能方法。
While likely not a fully reliable way, a screen reader's progress can be detected via javascript using the focus event, as the user skim through content.
A hidden "skip navigation link" (http://webaim.org/techniques/skipnav/) should it be focused, would be one way to detect whether someone is using a screenreader.
Even though it doesn't address the audio part of the question. I just wanted to provide this partial solution, as I was looking for possible ways to detect screen-readers myself.
您无法使用 JavaScript 检测屏幕阅读器,也无法使用任何客户端技术检测屏幕阅读器。您可以使用 Flash 检测运行 MSAA 客户端的软件。有关其工作原理以及为什么它没有用且不应用于检测屏幕阅读器的更多详细信息,请参阅此处:开发人员注意:使用 Flash 检测屏幕阅读器
You cannot detect screen readers using javascript, you cannot detect screen readers using any client side technology. You can detect software that is running an MSAA client using Flash. More details about how it works and why it is not useful and should not be used to detect screen readers is available here: Developer Beware: Using Flash to Detect Screen Readers