1. 程式人生 > >通過代碼實現自動判斷是手機端還是PC端跳轉

通過代碼實現自動判斷是手機端還是PC端跳轉

art con bag back indexof inf cati clas lan

 1 <!-- 2017/09/13 跳轉手機頁面 start by 小鬼PSer -->
 2 <meta name="mobile-agent" content="format=html5;url=http://forbag.inrn.net/kh1m.aspx">
 3 <script type="text/javascript">
 4     var userAgentInfo = navigator.userAgent;
 5     if  (userAgentInfo.indexOf("Android") > 0 || userAgentInfo.indexOf(
"iPhone") > 0 || userAgentInfo.indexOf("SymbianOS") > 0 || userAgentInfo.indexOf("Windows Phone") > 0 || userAgentInfo.indexOf("iPod") > 0 || userAgentInfo.indexOf("iPad") > 0) 6 { 7 window.location.href = "http://forbag.inrn.net/kh1m.aspx"; 8 }else { 9 } 10 </script
> 11 <!-- 2017/09/13 跳轉手機頁面 end by 小鬼PSer -->

將以上代碼插入到主頁源文件的區域之間,當用戶在手機端輸入網址http://forbag.inrn.net會直接跳入到http://forbag.inrn.net/kh1m.aspx的網頁內容。

通過代碼實現自動判斷是手機端還是PC端跳轉