通常情況下,使用window.navigator.cpuClass,可以在IE的時候返回x86或x64,來進行判斷系統是64位還是32位
但是,安裝64位Windows 7操作系統,使用IE 8執行腳本navigator.cpuClass返回x86而不是x64,但IE 9執行正常。
因此,更好的解決辦法如下:
客戶端環境最終極的方法是通過腳本執行navigator.userAgent來獲取用戶更多的客戶端環境信息。通過多台計算機的測試,發現在操作系統版本后出現WOW64或Win64信息,因此對原有判斷腳本進行兼容性改寫,可以解決上述問題。
相關示例代碼如下:
1 var agent = navigator.userAgent.toLowerCase(); 2 var isMac = function() { 3 return /macintosh|mac os x/i.test(navigator.userAgent); 4 }(); 5 if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) { 6 console("32位"); 7 }else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) { 8 console("64位"); 9 } 10 if(isMac){ 11 console("這是mac系統"); 12 }
參考文章:https://www.cnblogs.com/wasp520/archive/2012/07/11/2587012.html
https://blog.csdn.net/qq_37203608/article/details/82222179