简体   繁体   English

ASP.NET MVC - 如何检测用户是否使用屏幕阅读器

[英]ASP.NET MVC - How to detect if user is using a screen reader

So I'm currently trying to check if a user is using a screen reader on our site.所以我目前正在尝试检查用户是否在我们的网站上使用屏幕阅读器。 The reason I would like to check if they are is because our site provides a training module in which if they are using a screen reader, I would like to show a button that would allow them to download a printable version of the training.我想检查它们是否是因为我们的网站提供了一个培训模块,如果他们使用屏幕阅读器,我想显示一个按钮,允许他们下载培训的可打印版本。

Here is what I have tried so far:这是我迄今为止尝试过的:

internal class UnsafeNativeMethods
    {
        public const uint SPI_GETSCREENREADER = 0x0046;

        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
    }

    public static class ScreenReader
    {
        public static bool IsRunning
        {
            get
            {
                bool returnValue = false;
                if (!UnsafeNativeMethods.SystemParametersInfo(UnsafeNativeMethods.SPI_GETSCREENREADER, 0, ref returnValue, 0))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), "error calling SystemParametersInfo");
                }
                return returnValue;
            }
        }
    }

I snagged this code from the following StackOverflow thread: C# : How to detect if screen reader is running?我从以下 StackOverflow 线程中获取了此代码: C#:如何检测屏幕阅读器是否正在运行?

The method I'm using apparently works for some as you can see on this thread, but I'm currently always getting "false" when calling ScreenReader.IsRunning.我正在使用的方法显然适用于您在此线程上看到的某些方法,但我目前在调用 ScreenReader.IsRunning 时总是得到“false”。 I'm storing the ScreenReader.IsRunning value in a ViewBag and then in my view I'm using razor syntax to show a button if that value is true.我将 ScreenReader.IsRunning 值存储在 ViewBag 中,然后在我的视图中,如果该值为 true,我将使用 razor 语法显示一个按钮。 Not really sure why its always false.不太确定为什么它总是错误的。 I have tested this using JAWS as well as Narrator that comes on everyone's computer if you are using Windows 10 I think.如果您使用的是 Windows 10,我已经使用 JAWS 以及每个人的计算机上附带的讲述人对此进行了测试。 Any help would be much appreciated.任何帮助将非常感激。 Thank you all!谢谢你们!

It's not possible to detect whether a user is running a screenreader.无法检测用户是否正在运行屏幕阅读器。 If it were possible, it would open a door for unscrupulous types to home in on people with disabilities, or for a totally different "accessible" browser experience to be delivered, rather than building interfaces that are inclusive by design.如果可能的话,它将为不择手段的类型打开一扇门,让他们关注残疾人,或者为提供完全不同的“无障碍”浏览器体验,而不是构建设计上具有包容性的界面。

You could create a button that's placed off-screen but still in the tab order, and make it visible when it receives focus.您可以创建一个放置在屏幕外但仍按 Tab 键顺序放置的按钮,并在它获得焦点时使其可见。 Then blind users could find it, and sighted keyboard users wouldn't think something strange had happened when the button received focus.然后盲人用户可以找到它,视力正常的键盘用户不会认为当按钮获得焦点时发生了什么奇怪的事情。

I think you can only check if user has a chrome extensions or something like that working on client side with javascript.我认为你只能检查用户是否有 chrome 扩展或类似的东西在客户端使用 javascript 工作。

Idea : You can create an exe or a bath file for check users system and send information about this to your server.想法:您可以创建一个exe文件或一个用于检查用户系统的bath文件,并将有关此的信息发送到您的服务器。 If user download this file and there is no screen reader then load the page.如果用户下载此文件并且没有屏幕阅读器,则加载页面。 Otherwise give error about the screen reader.否则给出有关屏幕阅读器的错误。 And when response come from user computer maybe you can use SignalR for show content to user.当响应来自用户计算机时,也许您可​​以使用SignalR向用户显示内容。 You can make this file a must works in users system and start downloading this file when user load the page.您可以将此文件设为必须在用户系统中工作,并在用户加载页面时开始下载此文件。 Its not a good way but maybe you can check this with this way.这不是一个好方法,但也许您可以通过这种方式进行检查。

The HttpRequest.Browser property returns a HttpBrowserCapabilities object that enlists the capabilities of the device that has made the request. HttpRequest.Browser属性返回一个HttpBrowserCapabilities对象,对象征集发出请求的设备的功能。 Bear in mind that ASP.NET uses the User-Agent string sent as part of the HTTP request to identify a client.请记住,ASP.NET 使用作为 HTTP 请求的一部分发送的User-Agent字符串来标识客户端。 Then to populate the HttpBrowserCapabilities properties, ASP.NET processes the user-agent string using a set of pre-installed browser files, which are contained in the following location: %SystemRoot%\\Microsoft.NET\\Framework\\v4.0.30319\\CONFIG\\Browsers然后,为了填充 HttpBrowserCapabilities 属性,ASP.NET 使用一组预安装的浏览器文件处理用户代理字符串,这些文件包含在以下位置:%SystemRoot%\\Microsoft.NET\\Framework\\v4.0.30319\\CONFIG\\浏览器

HttpBrowserCapabilities Class HttpBrowserCapabilities 类

There are also third-parties which are far more detailed and updated with detecting device info, ie 51Degrees也有第三方提供的检测设备信息更加详细和更新,即51Degrees

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

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