如何通过JavaScript或CSS检查用户是否处于高对比度模式 [英] How to check if user is in high contrast mode via JavaScript or CSS

查看:275
本文介绍了如何通过JavaScript或CSS检查用户是否处于高对比度模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按下 Shift + 向左 + Alt + 打印 Windows切换到高对比度模式时,有机会在网页上检测到(使用JavaScript或CSS)?

When pressing Shift+Left+Alt+Print Windows switches into high contrast mode - is there any chance to detect that on a web page (using JavaScript or CSS)?

是否有机会检测到 HTTP-Request (也称为服务器端,例如通过PHP或Ruby)?

Is there any chance to detect that in the HTTP-Request (a.k.a the server-side e.g. via PHP or Ruby)?

推荐答案

http://hardlikesoftware.com/weblog/2009/11/04/css-sprites-vs-high-contrast-mode/rel =nofollow noreferrer>本文关于在高对比度使用CSS sprites ,在Windows的高对比度模式下,背景图片应设置为无,它也会更改背景颜色。这应该覆盖任何CSS样式表。所以你可以执行一些javascript来检测它在初始渲染后。请检查他的演示页面(高对比度模式下的[不是在高对比度模式下]文字)。

According to this article about using CSS sprites in high contrast, in high contrast mode on Windows, background images should be set to "none" and it also changes the background color. This should override any CSS stylesheet. So you can perform some javascript to detect it after initial rendering. Check his demo page (the "FYI [Not] in high contrast mode" text).

我有Mac(FYI切换使用 Cmd + Alt + Ctrl + 8 )和他的技术不工作

I have Mac (FYI switch using Cmd + Alt + Ctrl + 8) and his technique doesn't work for me, but he says it works on Windows.

如果它可以工作,你可以使用一些JavaScript来简单地更改你的CSS或者设置一个(会话)cookie并重新加载页面将其传递到服务器并执行服务器端操作。

If it works, you can either use some JavaScript to simply change your CSS or set a (session) cookie and reload the page to pass it to the server and perform server-side actions.

这篇关于如何通过JavaScript或CSS检查用户是否处于高对比度模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆