var OSName="Unknown OS"; 
if (navigator.appVersion.indexOf("Win")!=-1)
OSName="Windows";
else if (navigator.appVersion.indexOf("Mac")!=-1)
OSName="MacOS";
else if (navigator.appVersion.indexOf("X11")!=-1)
OSName="UNIX";
else if (navigator.appVersion.indexOf("Linux")!=-1)
OSName="Linux";

console.log('Your OS is: '+OSName);

参考链接:

https://stackoverflow.com/questions/14501185/detect-windows-vs-mac-os