How to find the operating system version using JavaScript?

后端 未结 13 900
滥情空心
滥情空心 2020-11-22 04:32

How can I find the OS name and OS version using JavaScript?

13条回答
  •  囚心锁ツ
    2020-11-22 05:19

    I can't comment on @Ian Ippolito answer (because I would have if I had the rep) but according to the document his comment linked, I'm fairly certain you can find the Chrome version for IOS. https://developer.chrome.com/multidevice/user-agent?hl=ja lists the UA as: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1

    So this should work:

    if ((verOffset = nAgt.indexOf('CriOS')) != -1) {
                    //Chrome on iPad spoofing Safari...correct it.
                    browser = 'Chrome';
                    version = nAgt.substring(verOffset + 6);//should get the criOS ver.
                }
    

    Haven't been able to test (otherwise I would have improved his answer) it to make sure since my iPad is at home and I'm at work, but I thought I'd put it out there.

提交回复
热议问题