如何通过 JavaScript 或 CSS 检查用户是否处于高对比度模式
当按 Shift+Left+Alt+Print 时,Windows 切换到高对比度模式 - 是否有机会检测到在网页上(使用 JavaScript 或 CSS)?
是否有机会在 HTTP-Request
(又名服务器端,例如通过 PHP 或 Ruby)中检测到这一点?
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)?
Is there any chance to detect that in the HTTP-Request
(a.k.a the server-side e.g. via PHP or Ruby)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 这篇关于在 high 中使用 CSS sprites 的文章对比度,在 Windows 上的高对比度模式下,背景图像应设置为“无”,并且它还会更改背景颜色。这应该覆盖任何 CSS 样式表。因此,您可以在初始渲染后执行一些 JavaScript 来检测它。检查他的演示页面(“仅供参考,[不]处于高对比度模式”文本)。
我有 Mac(仅供参考,使用
Cmd + Alt + Ctrl + 8 进行切换),他的技术对我不起作用,但他说它可以在 Windows 上工作。
如果它有效,您可以使用一些 JavaScript 来简单地更改 CSS 或设置(会话)cookie 并重新加载页面以将其传递到服务器并执行服务器端操作。
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).
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.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.
以下内容适用于我在带有(桌面)IE 的 Win8 上:
我认为它也必须适用于 Windows 应用商店应用程序。
这不是一个完整的解决方案,但可能有点用。
MSDN 文档:@media,
-ms-high-contrast。
高对比度模式 描述也值得一提。
The following works for me on Win8 with (the desktop-)IE:
I think it must work with Windows Store Apps as well.
This is not a complete solution, but maybe useful a bit.
MSDN doc: @media,
-ms-high-contrast.
The High-contrast mode description is also worth mentioning.
使用@media(prefers-contrast:更多)< /a>:
所有主流常青浏览器均支持。
警告:
-ms-high-contrast
仅适用于 Microsoft 浏览器。Use @media (prefers-contrast: more):
It's supported in all major evergreen browsers.
Warning:
-ms-high-contrast
only works in Microsoft browsers.如果您要在 Web 应用程序中实现高对比度,请使用以下代码块来检测白底黑字和黑底白字对比度选择。这在 IE 中可以正常工作。
@media screen and (-ms-high-contrast: black-on-white) {
/*
输入您的样式代码............
*/
}
@media 屏幕和 (-ms-high-contrast: 黑底白字) {
/*
输入您的样式代码............
*/
}
If you are implementing high contrast in your web application then use following code block for detecting black-on-white and white-on-black contrast selection. This will work fine in IE.
@media screen and (-ms-high-contrast: black-on-white) {
/*
Put your styling code.............
*/
}
@media screen and (-ms-high-contrast: white-on-black) {
/*
Put your styling code.............
*/
}