[TOC] #### 檢測當(dāng)前是否為移動設(shè)備 ```javascript /** * 檢測當(dāng)前是否為移動設(shè)備 * * @return true|false 是|否 */ function is_mobile() { // 其他類型的移動操作系統(tǒng)類型,自行添加 const os = ["Android", "iPhone", "Windows Phone", "iPod", "BlackBerry", "MeeGo", "SymbianOS"]; const info = navigator.userAgent; for (let i = 0; i < os.length; i++) { if (info.indexOf(os[i]) > 0) { return true; } } return false; } ``` #### 檢測是否為 ios 移動設(shè)備 ```javascript /** * 檢測是否為 ios 移動設(shè)備 */ function isIos() { const u = navigator.userAgent; if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) { return true; } return false; } ``` #### 檢測當(dāng)前是否為移動設(shè)備 以下代碼來自穿越火線官方活動頁面代碼 ```javascript function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; // 如果是移動設(shè)備,進(jìn)行調(diào)整到適用于移動端設(shè)備的頁面 if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) { window.location.href = "https://app.daoju.qq.com/act/a20240925pass/index.html" + location.search; } } ```