JS判斷當前設備是 PC IOS Andriod ...
JS判斷當前設備是 PC IOS Andriod
<script > window.onload = function(){ var isPc = IsPC(); var isAndroid = is_android(); if (isPc){ //pc location.href = url; }else{ if (isAndroid){ //安卓 location.href = ""; }else{ //IOS location.href = ""; } } } //如果返回的是false說明當前操作系統是手機端,如果返回的是true則說明當前的操作系統是電腦端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; } //如果返回true 則說明是Android false是ios function is_android() { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端 if (isAndroid) { //這個是安卓操作系統 return true; } if (isIOS) { //這個是ios操作系統 return false; } } </script>