武汉SEO
时光静好,与君语;细水流年,与君同;繁华落尽,与君老...

武汉SEO>正文

PC与移动端互跳代码

2019-02-21 13:11
<script>
var isPC = function (){
var userAgentInfo = navigator.userAgent.toLowerCase();
var Agents = new Array("android", "iphone", "symbianOS", "windows phone", "ipad", "ipod");
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
}
return flag;
}
var pcUlr = "http://www.0937.biz";
var mobleUlr = "http://m.0937.biz";
if(isPC()&&window.location.href.indexOf(mobleUlr)!=-1){
window.location.href = pcUlr+GetUrlRelativePath()
}else if(!isPC()&&window.location.href.indexOf(pcUlr)!=-1){
window.location.href = mobleUlr+GetUrlRelativePath()
}
function GetUrlRelativePath()
{
var url = document.location.toString();
var arrUrl = url.split("//");
var start = arrUrl[1].indexOf("/");
var relUrl = arrUrl[1].substring(start);//stop省略,截取从start开始到结尾的所有字符
if(relUrl.indexOf("?") != -1){
relUrl = relUrl.split("?")[0];
}
return relUrl;
}
</script>

本文链接:https://www.0937.biz/post-368.html