javascript判斷是什么系統(tǒng)的方法代碼:
// 判斷是什么系統(tǒng)
? ? function systemClass() {
? ? ? ? // 平臺、設(shè)備和操作系統(tǒng)
? ? ? ? var strFullPath = window.document.location.href;
? ? ? ? var system = {
? ? ? ? ? ? win: false,
? ? ? ? ? ? mac: false,
? ? ? ? ? ? x11: false
? ? ? ? }
? ? ? ? // 檢測平臺
? ? ? ? var p = navigator.platform;
? ? ? ? system.win = p.indexOf("Win") == 0;
? ? ? ? system.mac = p.indexOf("Mac") == 0;
? ? ? ? system.x11 = (p == "X11") || (p.indexOf("Linux") == 0)
? ? ? ? //跳轉(zhuǎn)語句,如果是手機訪問就自動跳轉(zhuǎn)到m.yydpt.com頁面
? ? ? ? if (system.win || system.mac || system.x11) {
? ? ? ? ? ? if (strFullPath.indexOf("http://m") == 0) {
? ? ? ? ? ? ? ? var Path = strFullPath.replace("http://m", "http://www");
? ? ? ? ? ? ? ? window.location.href = Path;
? ? ? ? ? ? }
? ? ? ? } else {
? ? ? ? ? ? if (strFullPath.indexOf("http://www") == 0) {
? ? ? ? ? ? ? ? var Path = strFullPath.replace("http://www", "http://m");
? ? ? ? ? ? ? ? window.location.href = Path;
? ? ? ? ? ? }
? ? ? ? }
? ? }
【systemClass】判斷是什么系統(tǒng)的方法名稱;
【navigator.platform】:聲明了運行瀏覽器的操作系統(tǒng)(或)硬件平臺;
【p.indexOf("Win") == 0】:表示的是Win系統(tǒng)的電腦上面的瀏覽器;
【p.indexOf("Mac") == 0】:表示的是Mac系統(tǒng)的電腦上面的瀏覽器;
【p.indexOf("Linux") == 0】:表示的是Linux系統(tǒng)的電腦上面的瀏覽器;
【system.win || system.mac || system.x11】:表示的是打開的瀏覽器如果在這幾個系統(tǒng)下就進入以上代碼中的方法,進行地址欄部分替換;