JS判断电脑端手机端自动跳转代码
JS判断电脑端手机端自动跳转代码,这段代码已经封装好了,不需要任何处理,复制引用就可以使用了。
相比网上的JS判断终端代码,这点代码是直接判断终端然后判断域名是否带blog.0735dj.com,带就跳转到m.0735dj.com
//是否是移动端 function is_mobile() { var regex_match = /(nokia iphone android motorola ^mot- softbank foma docomo kddi up.browser up.link htc dopod blazer netfront helio hosin huawei novarra CoolPad webos techfaith palmsource blackberry alcatel amoi ktouch nexian samsung ^sam- s[cg]h ^lge ericsson philips sagem wellcom bunjalloo maui symbian smartphone midp wap phone windows ce iemobile ^spice ^bird ^zte- longcos pantech gionee ^sie- portalmmm jigs browser hiptop ^benq haier ^lct operas*mobi opera*mini 320x320 240x320 176x220)/i; var u = navigator.userAgent; if (null == u) { return true; } var result = regex_match.exec(u); if (null == result) { return false } else { return true } } if (is_mobile()) { var s = window.location.href; if (s.indexOf("www")>0) { s = s.replace("www","m"); window.location.href=s; } else { s = s.replace("itbear","m.itbear"); window.location.href=s; } }所以你需要确保你的手机端是m.0735dj.com类型,如果不是就修改代码中的m为你的手机端二级域名
目录 返回
首页
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。