Detecting Chrome OS with Javascript

前端 未结 2 1584
小鲜肉
小鲜肉 2021-01-23 13:23

I want to detect Chrome OS with Javascript, and I\'m using navigator.userAgent for this. Now, I\'m running Chrome OS, and my navigator userAgent is



        
2条回答
  •  我在风中等你
    2021-01-23 14:14

    How about this?

    var chromeOS = /(CrOS)/.test(navigator.userAgent);
    

    Because a Chrome OS user agent looks like this:

    Mozilla/5.0 (X11; CrOS i686 0.12.433) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.77 Safari/534.30
    

    And filtering out "CrOS" is a good solution.

提交回复
热议问题