是否有一个CSS媒体查询来检测Windows? [英] Is there a CSS media query to detect Windows?

查看:212
本文介绍了是否有一个CSS媒体查询来检测Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想指定两种略有不同的背景颜色,一种用于Mac OS,一种用于Windows。

I want to specify two slightly different background colors, one for Mac OS, one for Windows.

推荐答案

属性来指定用于查看网页的操作系统,但您可以使用javascript检测它,下面是一些用于检测操作系统的示例:

there is no property to specify OS used to view webpage, but you can detect it with javascript, here is some example for detecting Operating system :

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

console.log('Your OS: '+OSName);

现在你可以使用 document.write 为特定的操作系统编写下载样式表。 :)

got it?, now you can play with document.write to write download stylesheet for specific Operating system. :)

另一个例子,我假设你正在使用jquery。

another example, i assumed that you are using jquery.

if (navigator.appVersion.indexOf("Win")!=-1) 
{
  $(body).css('background','#333');
} else {
  $(body).css('background','#000'); // this will style body for other OS (Linux/Mac)
}

这篇关于是否有一个CSS媒体查询来检测Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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