Heim > Fragen und Antworten > Hauptteil
在nodejs官网点击下载install,它是怎么判断我的电脑是32位还是64位的
ringa_lee2017-04-17 11:24:45
navigator.userAgent
,源码148行请自行查看。
window._gaq = [['_setAccount', 'UA-10874194-2'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
;(function(d,n) {
var os = n.platform.match(/(Win|Mac|Linux)/);
var x = n.userAgent.match(/x86_64|Win64|WOW64/) ||
n.cpuClass === 'x64' ? 'x64' : 'x86';
var base = 'http://nodejs.org/dist/v0.10.32/';
var href = 'node-v0.10.32.tar.gz';
var db = d.getElementById('downloadbutton');
var d2;
switch (os && os[1]) {
case 'Mac':
href = 'node-v0.10.32.pkg';
break;
case 'Win':
href = 'node-v0.10.32-' + x + '.msi';
if (x === 'x64') href = 'x64/' + href;
break;
// TODO uncomment when we have these
// case 'Linux':
// // two buttons: .deb and .rpm
// href = 'node-v0.10.32-' + x + '.rpm';
// var d2 = document.createElement('a');
// d2.href = base + 'node-v0.10.32-' + x + '.deb';
// d2.className = 'button downloadbutton';
// d2.innerHTML = 'INSTALL .deb';
// db.innerHTML = 'INSTALL .rpm';
// db.parentNode.insertBefore(d2, db);
// break;
}
db.href = base + href;
// if there's one download option, then download it at #download
if (location.hash === '#download' && !d2)
location.replace(b.href);
})(document,navigator);
天蓬老师2017-04-17 11:24:45
用userAgent:
console.log(navigator.userAgent);
在64位Linux下(我的电脑)显示是
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
基本上,如果是64位,就会有x86_64或64bit字样。反之则是32位的。