www网址判断手机跳m
<script src="/style/js/jumpmobile.js" type="text/javascript"></script>
<script>
redirectMobile();
</script>
*强调内容*/自动跳m端
redirectMobile = function() {
var nowUrl = location.href,
nowHost = location.host,
nowPathname = location.pathname,
jumpUrl = '',
mobileUrl = 'http://m.danji6.com';
mobileHurl = GetUrlRelativePath()
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) { try {
if (nowUrl == 'http://www.danji6.com/') {
jumpUrl = mobileUrl;
}else if (nowHost != 'm.danji6.com') {
var match = nowPathname.match(/^\/[a-zA-Z0-9]*\/(.*)?/i);
if (match != null) jumpUrl = mobileUrl + mobileHurl;
}
if (jumpUrl) location.href = jumpUrl;
} catch (e) { }
}
}
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;
}
本文作者:蜗牛使劲冲
本文链接:https://www.cnblogs.com/warrenwt/p/18074699
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步