js判断操作系统
Posted Jay_帅小伙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js判断操作系统相关的知识,希望对你有一定的参考价值。
/**
* 判断操作系统
*/
export function detectOS()
const sUserAgent = navigator.userAgent
const isWin =
navigator.platform === 'Win32' || navigator.platform === 'Windows'
const isMac =
navigator.platform === 'Mac68K' ||
navigator.platform === 'MacPPC' ||
navigator.platform === 'Macintosh' ||
navigator.platform === 'MacIntel'
if (isMac) return 'Mac'
var isUnix = navigator.platform === 'X11' && !isWin && !isMac
if (isUnix) return 'Unix'
var isLinux = String(navigator.platform).indexOf('Linux') > -1
if (isLinux) return 'Linux'
if (isWin)
var isWin2K =
sUserAgent.indexOf('Windows NT 5.0') > -1 ||
sUserAgent.indexOf('Windows 2000') > -1
if (isWin2K) return 'Windows 2000'
var isWinXP =
sUserAgent.indexOf('Windows NT 5.1') > -1 ||
sUserAgent.indexOf('Windows XP') > -1
if (isWinXP) return 'Windows XP'
var isWin2003 =
sUserAgent.indexOf('Windows NT 5.2') > -1 ||
sUserAgent.indexOf('Windows 2003') > -1
if (isWin2003) return 'Windows 2003'
var isWinVista =
sUserAgent.indexOf('Windows NT 6.0') > -1 ||
sUserAgent.indexOf('Windows Vista') > -1
if (isWinVista) return 'Windows Vista'
var isWin7 =
sUserAgent.indexOf('Windows NT 6.1') > -1 ||
sUserAgent.indexOf('Windows 7') > -1
if (isWin7) return 'Windows 7'
var isWin8 = sUserAgent.indexOf('Windows NT 8.1') > -1
if (isWin8) return 'Windows 8'
var isWin10 = sUserAgent.indexOf('Windows NT 10.0') > -1
if (isWin10) return 'Windows 10'
return 'Unknown'
以上是关于js判断操作系统的主要内容,如果未能解决你的问题,请参考以下文章