騰訊首頁分辨手機端與pc端代碼

騰訊首頁分辨手機端與pc端代碼

  本身在作網頁的時候在騰訊網首頁借鑑的代碼.javascript

  代碼:css

 1 <!-- 移動適配JS腳本 -->
 2     <script type="text/javascript">
 3         if (window.location.toString().indexOf('pref=padindex') != -1) {
 4         } else {
 5             if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /\(Android.*Mobile.+\).+Gecko.+Firefox/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
 6                 if (window.location.href.indexOf("?mobile")<0){
 7                     try {
 8                         if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
 9                             window.location.href="https://www.xiyixu.top/mobile_index.html";
10                         } else if (/iPad/i.test(navigator.userAgent)) {
11                             //window.location.href=""
12                         } else {
13                             window.location.href="https://www.xiyixu.top/simple_index.html"
14                         }
15                     } catch (e) {}
16                 }
17             }
18         }
19     </script><!--[if !IE]>|xGv00|6a478dd274c352466ec1a24404f6e978<![endif]-->

看法:html

if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent))
此句判斷打開網頁的設備是否爲Android|Windows Phone|webOS|iPhone|iPod|這些設備,若是是,則指向一個新的網頁,若是不是則繼續執行.

代碼源自騰訊網首頁java

2018年10月9日18:7:16web

相關文章
相關標籤/搜索