js判斷手機訪問或者PC的幾個例子(常用于手機跳轉(zhuǎn))
例子一
<script> function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){ window.location.href='http://chabaoo.cn'; }else{ //window.location.; } } $(function(){ browserRedirect(); }); </script>
例子2
<script type="text/javascript"> (function(){ var reWriteUrl = function(url){ if(url){ var Splits = url.split("/"),siteName=window.location.pathname; if(typeof siteName!=="undefined"){ return "http://m.jb51.net"+siteName; } } }; if(/Android|webOS|iPhone|iPad|Windows Phone|iPod|BlackBerry|SymbianOS|Nokia|Mobile/i.test(navigator.userAgent)){ var url=window.location.href; var pathname=window.location.pathname; if(url.indexOf("?mobile")<0){ try{ window.location.href=reWriteUrl(url); }catch(e){} } }; })(); </script>
注意,如果給搜索引擎看的話我們在文件頭加入
<meta http-equiv="mobile-agent" content="format=xhtml; url=http://m.jb51.net" />
<meta http-equiv="mobile-agent" content="format=html5; url=http://m.jb51.net" />
意思是告訴搜索引擎移動蜘蛛抓取的是手機版本的.
- JS如何實現(xiàn)網(wǎng)站中PC端和手機端自動識別并跳轉(zhuǎn)對應(yīng)的代碼
- JS前端開發(fā)判斷是否是手機端并跳轉(zhuǎn)操作(小結(jié))
- JS跳轉(zhuǎn)手機站url的若干注意事項
- js根據(jù)手機客戶端瀏覽器類型,判斷跳轉(zhuǎn)官網(wǎng)/手機網(wǎng)站多個實例代碼
- 基于JavaScript代碼實現(xiàn)pc與手機之間的跳轉(zhuǎn)
- 兩款JS腳本判斷手機瀏覽器類型跳轉(zhuǎn)WAP手機網(wǎng)站
- JS腳本根據(jù)手機瀏覽器類型跳轉(zhuǎn)WAP手機網(wǎng)站(兩種方式)
- JSP中實現(xiàn)判斷客戶端手機類型并跳轉(zhuǎn)到app下載頁面
- 百度判斷手機終端并自動跳轉(zhuǎn)js代碼及使用實例
- 手機平板等移動端適配跳轉(zhuǎn)URL的js代碼
- JS自動跳轉(zhuǎn)手機移動網(wǎng)頁的實現(xiàn)方法
相關(guān)文章
JavaScript style對象與CurrentStyle對象案例詳解
這篇文章主要介紹了JavaScript style對象與CurrentStyle對象案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08JS實現(xiàn)移動端實時監(jiān)聽輸入框變化的實例代碼
這篇文章主要介紹了JS實現(xiàn)移動端實時監(jiān)聽輸入框變化的解決方案,需要的朋友可以參考下2017-04-04理解javascript中的Function.prototype.bind的方法
這篇文章主要介紹了理解javascript中的Function.prototype.bind的方法,具有一定參考價值,有興趣的可以了解一下。2017-02-02ES6中的class是如何實現(xiàn)的(附Babel編譯的ES5代碼詳解)
這篇文章主要介紹了ES6中的class是如何實現(xiàn)的?(附Babel編譯的ES5代碼詳解),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05JavaScript檢測字符串中是否含有html標簽實現(xiàn)方法
這篇文章主要介紹了JavaScript檢測字符串中是否含有html標簽實現(xiàn)方法,本文直接給出實現(xiàn)代碼,需要的朋友可以參考下2015-07-07javascript延時重復執(zhí)行函數(shù) lLoopRun.js
javascript延時重復執(zhí)行函數(shù) lLoopRun.js...2007-06-06