User Agent 또는 Javascript에서 64 비트 또는 32 비트 Windows를 감지 하시겠습니까?
올바른 버전의 다운로드를 제공하고 싶습니다. 내가 가지고있는 버전은 다음과 같습니다.
- 32 비트 Windows
- 64 비트 Windows
- 리눅스
User Agent 필드를 사용하여 Linux를 감지하는 것은 쉽습니다. 그러나 Windows가 32 비트인지 64 비트인지 확실하게 파악할 수 있습니까?
사용자는 이상한 브라우저를 사용하고있을 수 있습니다. IE와 Firefox는 일반적이며 어딘가에 Opera 사용자가있을 것입니다. Chrome 사용자 일 수도 있습니다. 64 비트 Windows 7이 32 비트 및 64 비트 버전의 IE와 함께 제공된다는 것을 알고 있으며, 두 버전 모두 내 다운로드의 64 비트 버전을 보내고 싶습니다.
(추가로 편집 : 모든 옵션을 제공해야한다는 것을 알고 있습니다.하지만 사람들은 옵션을 읽지 않습니다 . 따라서 기본적으로 올바른 다운로드를 제공하여 유용성을 높이고 싶었습니다. 물론 이것은 도움이되지만 내가 옳다면, 내가 틀렸다면 그것은 매우 도움이되지 않습니다. 그리고 지금까지의 대답을 보면 믿을만한 방법이없는 것 같습니다.)
이를 시도하여 사용자 에이전트 문자열에서 WOW64 (64 비트에서 32 비트) 또는 Win64 (기본 64 비트)를 찾습니다.
if (navigator.userAgent.indexOf("WOW64") != -1 ||
navigator.userAgent.indexOf("Win64") != -1 ){
alert("This is a 64 bit OS");
} else {
alert("Not a 64 bit OS");
}
몇 가지 테스트를했습니다. 결과는 다음과 같습니다. 도움이되기를 바랍니다.
64 비트 MacOS + 64 비트 Safari 또는 32 비트 Chrome : window.navigator.platform = MacIntel 32 비트 Windows + Safari : window.navigator.platform = Win32 64 비트 Windows + 64 비트 IE : window.navigator.platform = Win64 window.navigator.cpuClass = x64 64 비트 Windows + 32 비트 IE : window.navigator.platform = Win32 window.navigator.cpuClass = x86 64 비트 Windows + 32 Firefox (또는 Chrome) : window.navigator.platform = Win32 32 비트 Linux Mint (i686) + Firefox : window.navigator.platform = 리눅스 i686 64 비트 Ubuntu (x86_64) + 32 비트 Chrome : window.navigator.platform = 리눅스 i686 64 비트 Ubuntu + 64 비트 Epiphany : window.navigator.platform = Linux x86_64
지금까지이 코드를 사용했습니다.
deployJava.isWin64OS = function() {
return navigator.userAgent.indexOf('WOW64')>-1 || window.navigator.platform=='Win64';
};
약 14000 개의 고유 한 사용자 에이전트 ( 여기에서 )를 분석 하여 다음 문자열을 찾아 보았습니다.
- x86_64
- x86-64
- Win64
- x64; (세미콜론을 생각하십시오! 그것이 없으면 거짓 양성이 될 것입니다.)
- amd64
- AMD64
- WOW64
- x64_64
또한 명령어 세트가 다르고 Intel x86_64와 호환되지 않지만 다음을 감지 할 수 있습니다.
- ia64
- sparc64
- ppc64
- IRIX64
하지만 "64"또는 "x64"가 포함 된 것을 찾지 마십시오. Chrome의 빌드 번호, 스파이더 / 봇, 라이브러리, .NET 버전, 해상도 등은 여전히 32 비트 (또는 기타) OS 인 동시에 문자열 'x64'를 포함 할 수 있습니다.
모든 문자열을 대소 문자를 구분하지 않고 검색 할 수 있습니다.
ARM에서 아무것도 찾을 수 없었습니다. 다른 사람일까요? 편집하세요. 커뮤니티 위키입니다.
당신은 확인할 수 window.navigator.platform
와를 window.navigator.cpuClass
.
귀하의 상황은 확실하지 않지만 대부분의 다른 사이트에서 수행하는 작업을 고려하고 사용자가 다운로드 할 다운로드를 선택할 수 있도록합니다. 그들은 다른 컴퓨터를 위해 그것을 다운로드하거나 플래시 장치에 넣을 수도 있고 단순히 32 비트 버전이 64 비트 상자에서 실행되기를 원할 수도 있습니다. 이유가 무엇이든 저는 선택권을 갖고 싶습니다.
가장 안정적인 솔루션은 아키텍처를 감지 한 다음 적절한 버전의 애플리케이션을 다운로드하고 설치하는 32 비트 로더 애플리케이션을 만드는 것입니다.
RC와 Pino의 다른 두 답변을 확인했습니다. 제안한 것과 동일한 문제로 인해 둘 다 작동하지 않습니다. 64 비트 Windows의 32 비트 IE는 플랫폼을 32 비트로 잘못 식별합니다. 대부분의 사람들이 64 비트 Windows에서 32 비트 IE를 실행하기 때문에 (플래시와 같은 많은 플러그인은 64 비트에서 사용할 수 없음) 많은 고유 식별 정보가 있습니다.
남자 이름
브라우저는 32 비트 버전이고 OS는 64 비트 일 수 있다고 말했듯이 100 % 확실하지 않습니다.
브라우저를 감지하려면 다음 코드를 시도하십시오.
<script language=javascript>
<!--
document.write("CPU :"+window.navigator.cpuClass);
//-->
</script>
CPU : ia64
IE의 경우.
http://msdn.microsoft.com/en-us/library/ms531090%28VS.85%29.aspx
상용 제품 : https://www.cyscape.com/showbrow.aspx
For 64-bit Windows with 64-bit IE window.navigator.platform
will be "Win64" and window.navigator.cpuClass
will be "x64".
For 64-bit Windows with 32-bit IE, window.navigator.platform
will be "Win32" and window.navigator.cpuClass
will be "x86".
For 32-bit Windows, window.navigator.platform
will be "Win32" and window.navigator.cpuClass
will be undefined (I think).
-
Source: I made an app that uses JavaScript to determine if someone is using a 32 bit or 64 bit processor. You can see the code here on GitHub.
I resumed the results of the nice search above into these JS functions. Hope they can help everybody here to catch up a quick response to their needs (and, as well, to mine too !)
function get_bits_system_architecture()
{
var _to_check = [] ;
if ( window.navigator.cpuClass ) _to_check.push( ( window.navigator.cpuClass + "" ).toLowerCase() ) ;
if ( window.navigator.platform ) _to_check.push( ( window.navigator.platform + "" ).toLowerCase() ) ;
if ( navigator.userAgent ) _to_check.push( ( navigator.userAgent + "" ).toLowerCase() ) ;
var _64bits_signatures = [ "x86_64", "x86-64", "Win64", "x64;", "amd64", "AMD64", "WOW64", "x64_64", "ia64", "sparc64", "ppc64", "IRIX64" ] ;
var _bits = 32, _i, _c ;
outer_loop:
for( var _c = 0 ; _c < _to_check.length ; _c++ )
{
for( _i = 0 ; _i < _64bits_signatures.length ; _i++ )
{
if ( _to_check[_c].indexOf( _64bits_signatures[_i].toLowerCase() ) != -1 )
{
_bits = 64 ;
break outer_loop;
}
}
}
return _bits ;
}
function is_32bits_architecture() { return get_bits_system_architecture() == 32 ? 1 : 0 ; }
function is_64bits_architecture() { return get_bits_system_architecture() == 64 ? 1 : 0 ; }
Test it:
document.write( "Which is my current bits system architecture ? " + get_bits_system_architecture() + "<br>" );
document.write( "Is it 32 bits ? " + ( is_32bits_architecture() ? "YES" : "NO" ) + "<br>" );
document.write( "Is it 64 bits ? " + ( is_64bits_architecture() ? "YES" : "NO" ) );
Thanks to everyone!
I used following code:
var is32BitBrowser = true;
if( window.navigator.cpuClass != null && window.navigator.cpuClass.toLowerCase() == "x64" )
is32BitBrowser = false;
if( window.navigator.platform.toLowerCase() == "win64" )
is32BitBrowser = false;
It worked everywhere expect Mac computers. And unfortunately seems that it's not possible to get that information via JavaScript :(. However one more trick could be done there. Because Adobe didn't support flash player on x64 browsers, you can just try to detect it. If detection is successful, than it is definitely 32 bit browser, if no, than it's 32 bit browser without flash plugin or it's 64 bit browser. Because penetration rate of Flash player is quite huge(see http://www.adobe.com/products/player_census/flashplayer/version_penetration.html), this should be good enough to at least detect x32 browser under Mac.
64-bit IE on 64-bit Windows for any Internet Explorer browser
if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Win64") != -1 && navigator.userAgent.indexOf("x64") != -1){
alert("This is 64 bit browser");
}
else {
alert("Not 64 bit browser");
}
Both window.navigator.cpuClass and window.navigator.platform return the browser platform. Not the system platform. So if you are running a 32-bit browser on a 64-bit system then both varibales would return 32-bit. Which would be incorrect.
I've found this old question and thought updating with a recent open source library I found: https://github.com/faisalman/ua-parser-js
According to the docs, the method getCPU()
returns { architecture: '' }
, with the following possible values: 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc, ppc, sparc, sparc64
.
'development' 카테고리의 다른 글
Angular2에서 구독을 취소하는 방법 (0) | 2020.10.18 |
---|---|
#pragma가 한 번 자동으로 가정되지 않는 이유는 무엇입니까? (0) | 2020.10.18 |
ContextSwitchDeadlock이 C #에서 오류를 감지했습니다. (0) | 2020.10.18 |
둘 이상의 필드가있는 LINQ OrderBy (0) | 2020.10.18 |
TLS 1.2의 .NET 구현이 있습니까? (0) | 2020.10.18 |