欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

wap浏览自动跳转到wap页面的js代码_javascript技巧

程序员文章站 2022-03-26 23:38:18
...
如何让用户输入wap手机网站的网址时自动跳转到wap网站 ?
wap页面自动跳转的实现方式 ?
如何判断访客是否是移动设备访问,自动跳转到wap页面 ?
手机自动跳转到手机页面,一个网址区分普通访问与手机访问 ?
手机访问网站域名时如果实现自动跳转到wap页面 ?

本文就可以解决这些问题!

复制代码 代码如下:

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()) {
document.location.href= '/wap';
}

以上是js代码 只需要将/wap改成你需要跳转到的页面就可以了