是否可以使用 javascript 来检测屏幕阅读器是否在用户机器上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7712167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to use javascript to detect if a screen reader is running on a users machine?
提问by shuklendu
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.
我想检测屏幕阅读器是否正在用户机器上运行,以避免声音与 html 中的音频标签发生冲突。如果是这样,请提供有关如何做到这一点的详细信息。
采纳答案by BrendanMcK
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.
即使您可以检测到屏幕阅读器正在运行,您也不应该尝试做任何特殊的事情。即使您对一组屏幕阅读器用户来说是正确的,对于另一组用户来说也可能是错误的。最好一开始就专注于编写干净的 HTML5。
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.
请注意,并非所有屏幕阅读器用户都使用文本转语音;许多使用盲文输出。此外,其他类型的辅助功能工具——例如内容荧光笔和语音输入应用程序——使用与屏幕阅读器相同的技术和 API(例如 DOM、MSAA),因此任何“检测屏幕阅读器”的技术也可能会检测到这些——所以您不能假设这意味着用户完全失明并且只使用语音。
As things currently stand, the audio tag is currently not universally accessible, different browsers have different levels of accessibility support - see HTML5 Accessibilityand 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.)
就目前的情况而言,音频标签目前并非普遍可访问,不同的浏览器具有不同级别的可访问性支持 - 请参阅HTML5 可访问性并向下滚动到音频以了解当前支持的更多详细信息。我已经看到一些页面在音频标签之后添加了基于 HTML5 的控件和 javascript,这样他们就可以提供自己的 UI,以确保键盘或屏幕阅读器用户可以根据需要播放/停止音频。(最终,当浏览器赶上时,这应该是不需要的。)
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.)
就一般可访问性而言,WCAG 2.0(Web 内容可访问性指南)建议任何自动播放超过 3 秒的音频都应具有暂停或停止音频的可访问方式。(我会更进一步并建议不要使用任何自动音频 - 使用标签浏览时,通常无法确定音频来自哪个标签。)
回答by Steve Faulkner
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 MSAAclient 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
您无法使用 javascript 检测屏幕阅读器,也无法使用任何客户端技术检测屏幕阅读器。您可以使用 Flash检测运行MSAA客户端的软件。有关它的工作原理以及为什么它没有用且不应用于检测屏幕阅读器的更多详细信息,请访问此处:开发人员注意:使用 Flash 检测屏幕阅读器
回答by hexalys
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 though content.
虽然可能不是一种完全可靠的方式,但当用户浏览内容时,可以通过 javascript 使用 focus 事件检测屏幕阅读器的进度。
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.
一个隐藏的“跳过导航链接”(http://webaim.org/techniques/skipnav/)应该被聚焦,这将是检测是否有人在使用屏幕阅读器的一种方法。
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.
尽管它没有解决问题的音频部分,但我只是想提供这个部分解决方案,因为我正在寻找自己检测屏幕阅读器的可能方法。