uaredirect.js 進行判斷是pc還是wap端(移動端) wap端跳轉頁面
阿新 • • 發佈:2019-01-07
在pc的網址裡面加入程式碼
<script src=
"http://siteapp.baidu.com/static/webappservice/uaredirect.js"
type=
"text/javascript"
></script>
<script type="text/javascript">uaredirect("http://wap.tongji021.com");</script>
第一個script 是為了引用百度的js程式碼
第二個script就是跳轉到你想要跳轉的wap頁面
這樣就能實現 wap訪問之時 跳轉到你想跳轉的頁面
參考:http://vr013.com/
---------------------------------------------分隔符--------------------------------
批量替換把www換成m
function mobile_device_detect(url) { var thisOS=navigator.platform; var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile"); for(var i=0;i<os.length;i++) { if(thisOS.match(os[i])) { window.location=url; } } //因為相當部分的手機系統不知道資訊,這裡是做臨時性特殊辨認 if(navigator.platform.indexOf('iPad') != -1) { window.location=url; } //做這一部分是因為Android手機的核心也是Linux //但是navigator.platform顯示資訊不盡相同情況繁多,因此從瀏覽器下手,即用navigator.appVersion資訊做判斷 var check = navigator.appVersion; if( check.match(/linux/i) ) { //X11是UC瀏覽器的平臺 ,如果有其他特殊瀏覽器也可以附加上條件 if(check.match(/mobile/i) || check.match(/X11/i)) { window.location=url; } } //類in_array函式 Array.prototype.in_array = function(e) { for(i=0;i<this.length;i++) { if(this[i] == e) return true; } return false; } } var url = window.location.href; url = url.replace("www.", "m."); mobile_device_detect(url);