手機端自適應屏幕跳轉到指定的地址,js代碼(已經測試)和php代碼javascript
js代碼: <script type="text/javascript"> var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire"); var browser = navigator.userAgent.toLowerCase(); var isMobile = false; for (var i=0; i<mobileAgent.length; i++){ if (browser.indexOf(mobileAgent[i])!=-1){ isMobile = true;//alert(mobileAgent[i]);location.href = 'https://www.qsyidai.com/m';break; } } </script> php代碼: //設定Mobile的定義 $mobileAgent = array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire"); //讀取用戶的瀏覽器資料 $browser = $_SERVER['HTTP_USER_AGENT']; $isMobile = false; //檢查開始 foreach($mobileAgent as $search){ if(stristr($browser,$search)!=false){ $isMobile = true; //echo $search; //程式碼(轉址) header("Location: https://www.qsyidai.com/m"); //中止運行程序 exit; } } ?>