可能重複:
How to find the operating system version using JavaScriptOS和OS版本檢測在JavaScript
我怎麼可以檢測到使用javascrtip其中OS和OS版本,我的客人。例如Windows Vista或七或Xp和Linux也是如此。
可能重複:
How to find the operating system version using JavaScriptOS和OS版本檢測在JavaScript
我怎麼可以檢測到使用javascrtip其中OS和OS版本,我的客人。例如Windows Vista或七或Xp和Linux也是如此。
navigator.platform會爲您提供他們正在使用的當前平臺,就像navigator.userAgent會爲您提供整個瀏覽器字符串一樣。
要檢測客戶機上的操作系統,您的腳本應該分析navigator.appVersion字符串。以下是一個腳本的簡單示例,它將變量OSName設置爲反映實際的客戶端操作系統。
// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
在系統上,該腳本將產生以下結果: 您的操作系統:Windows
(要獲得更詳細的系統信息,你的腳本應該執行navigator.appVersion
串的更復雜的分析,但想法將是相同的。)
在Firefox/WinXP上輸出navigator.appVersion
。
5.0 (Windows; en-US)
在Firefox/WinXP上輸出navigator.userAgent
。
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
的navigator.platform
Win32
請舉個例子。瞭解它對我很重要 – 2011-03-03 16:03:19
輸出僅工作在Firefox,而不是鍍鉻 – gkmohit 2016-08-26 03:02:15