不忘初心 牢记使命
网络强国 科技创新
分享一段js判断手机访问并跳转到手机版网页代码
<script type="text/javascript"> function redirectMobile() { var nowUrl = location.href, nowHost = location.host, nowPathname = location.pathname, jumpUrl = '', mobileUrl = 'http://m.5ixuexiwang.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.5ixuexiwang.com/') { jumpUrl = mobileUrl; } else if (nowHost != 'm.5ixuexiwang.com') { 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); return relUrl; } redirectMobile(); </script>
咨询热线
地址:深圳市福田区南园路68号上步大厦18A 特别声明: 本会所有证书与官网一致为准。