How to find the operating system version using JavaScript?

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

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

13条回答
  •  盖世英雄少女心
    2020-11-22 05:18

    platform.js seems like a good one file library to do this.

    Usage example:

    // on IE10 x86 platform preview running in IE7 compatibility mode on Windows 7 64 bit edition
    platform.name; // 'IE'
    platform.version; // '10.0'
    platform.layout; // 'Trident'
    platform.os; // 'Windows Server 2008 R2 / 7 x64'
    platform.description; // 'IE 10.0 x86 (platform preview; running in IE 7 mode) on Windows Server 2008 R2 / 7 x64'
    
    // or on an iPad
    platform.name; // 'Safari'
    platform.version; // '5.1'
    platform.product; // 'iPad'
    platform.manufacturer; // 'Apple'
    platform.layout; // 'WebKit'
    platform.os; // 'iOS 5.0'
    platform.description; // 'Safari 5.1 on Apple iPad (iOS 5.0)'
    
    // or parsing a given UA string
    var info = platform.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.2; en; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 11.52');
    info.name; // 'Opera'
    info.version; // '11.52'
    info.layout; // 'Presto'
    info.os; // 'Mac OS X 10.7.2'
    info.description; // 'Opera 11.52 (identifying as Firefox 4.0) on Mac OS X 10.7.2'
    

提交回复
热议问题