Is there a CSS media query to detect Windows?

前端 未结 4 1650
天命终不由人
天命终不由人 2020-12-03 09:56

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

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 10:40

    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);
    

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

    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)
    }
    

提交回复
热议问题