wordpress教程:手机访问电脑站点自动跳转到手机站点
时间:2年前 游览量:591 标签: nbsp quot com 适合 replace
首先申明,此教程不仅仅只适合wordpress,一切的网页程序都适合
大致的需求是:有的时候,比如在手机设备上,输入了www.bokebu.com 想自动跳转到 m.bokebu.com 手机站点上,那么以下js代码,就可以插入电脑站点的head上了。。。
<script>
function uaredirect(murl){
try{
if(document.getElementById("bdmark") != null) {
return
}
var urlhash = window.location.hash;
if(!urlhash.match("fromapp")){
if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))){
if( murl.indexOf("www.bokebu.com") ){
murl = murl.replace("www.bokebut.com","m.bokebu.com");
}
location.replace(murl);
}
}
}catch(err){}
}
uaredirect(window.location.href);
</script>
教程清晰简单,自己替换里面的相关域名为自己的!