經過JS語句判斷WEB網站的訪問端是電腦仍是手機,以顯示不一樣的頁面!javascript
1 <script type="text/javascript"> 2 <!-- 3 //平臺、設備和操做系統 4 var system = { 5 win: false, 6 mac: false, 7 xll: false, 8 ipad:false 9 }; 10 //檢測平臺 11 var p = navigator.platform; 12 system.win = p.indexOf("Win") == 0; 13 system.mac = p.indexOf("Mac") == 0; 14 system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); 15 system.ipad = (navigator.userAgent.match(/iPad/i) != null)?true:false; 16 //跳轉語句,若是是手機訪問就自動跳轉到wap.baidu.com頁面 17 if (system.win || system.mac || system.xll||system.ipad) { 18 19 } else { 20 21 window.location.href = "http://www.jdpatro.com/3g/"; 22 } 23 --> 24 </script>