方法介绍: 

js通过获取navigator.userAgent当前电脑系统版本:window7~10/mac/Unix/Linux-Qui-Note

通过window.navigator.userAgent获取当前浏览器及系统信息,返回的结果如下:

 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

因此,只需判断返回的字符串是否含有指定版本名字就知道当前电脑的系统版本了

测试代码:

function getUserAgent(){
	 let e = "Unknown";
	 if (window.navigator.userAgent.indexOf("Windows NT 10.0") != -1)
	      e = "Windows 10";
	  if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1)
	      e = "Windows 8";
	  if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1)
	      e = "Windows 7";
	  if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1)
	      e = "Windows Vista";
	  if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1)
	      e = "Windows XP";
	  if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1)
	      e = "Windows 2000";
	  if (window.navigator.userAgent.indexOf("Mac") != -1)
	      e = "Mac/iOS";
	  if (window.navigator.userAgent.indexOf("X11") != -1)
	      e = "UNIX";
	  if (window.navigator.userAgent.indexOf("Linux") != -1)
	      e = "Linux";
	  return e
}
console.log(getUserAgent())

 不过这个方法也不太精准,比如我的电脑是win11,通过浏览器获取到的竟然是win10,哈哈哈,仅供学习娱乐,做统计的话估计有错误,不严谨!!!