我需要使用Javascript获取桌面信息,可能是Windows,MAC,Linux操作系统。我需要获取系统唯一ID,操作系统名称等,例如,在移动设备中我们可以获取设备ID,以同样的方式,是否有可能获得桌面的唯一ID?
答案 0 :(得分:0)
JavaScript无权访问。您可以做的更接近navigator.userAgent
。
console.log(navigator.userAgent);
您所能做的就是询问一个可以使用XMLHttpRequest
答案 1 :(得分:0)
var parser = new UAParser();
window.navigator.userAgent
console.log(parser.getResult());
// let's test a custom user-agent string as an example
var uastring = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu / 11.10 Chromium / 15.0 .874 .106 Chrome / 15.0 .874 .106 Safari / 535.2 ";
parser.setUA(uastring);
var result = parser.getResult();
// this will also produce the same result (without instantiation):
// var result = UAParser(uastring);
console.log(result.browser); // {name: "Chromium", version: "15.0.874.106" }
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined }
console.log(result.os); // {name: "Ubuntu", version: "11.10"}
console.log(result.os.version); // "11.10"
console.log(result.engine.name); // "WebKit"
console.log(result.cpu.architecture); // "amd64"
// do some other tests
var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
var uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US)AppleWebKit / 534.11(KHTML, like Gecko) Version / 7.1 .0 .7 Safari / 534.11 ';
console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
console.log(parser.getOS()) // {name: "RIM Tablet OS ", version: "1.0.0"}
console.log(parser.getBrowser().name); // "Safari"
<!doctype html>
<html>
<head>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ua-parser-js@0.7.19/src/ua-parser.min.js"></script>
</head>
<body>
</body>
</html>
答案 2 :(得分:0)
我们可以使用Java Script访问操作系统名称。您可以访问此链接。
http://www.javascripter.net/faq/operatin.htm