4G降临,移动网站已经一发不可收拾,pc端和移动端官网并存。如何让别人访问你的pc端的官网直接跳转到移动端的网站呢?各位看官,小二上代码!来了!
var url = window.location.href;
var url_match = /vit=1$/i;
if (!url.match(url_match)){
if(navigator.userAgent.match(/(operamini|ipad|ipod|iphone|android|webOS|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|hiptop|pda|psp|treo|nokia|blackberry)/i)){
location.replace("/wap.php");
}
}
function uaredirect(murl){
try {
if(document.getElementById("bdmark") != null){
return;
}
var urlhash = window.location.hash;
if (!urlhash.match("fromapp")){
if ((navigator.userAgent.match(/(iPhone|240x320|acer|tianyu|iPod|Android|ios|iPad|mobile|Mobi)/i))) {
location.replace(murl);
}
}
} catch(err){}
}
uaredirect("/wap.php");