html自动跳转手机,手机浏览网站自动跳转到wap页面的代码

手机访问网站域名时如果实现自动跳转到wap页面 ?

如何让用户输入wap手机网站的网址时自动跳转到wap网站 ?

wap页面自动跳转的实现方式 ?

如何判断访客是否是移动设备访问,自动跳转到wap页面 ?

手机自动跳转到手机页面,一个网址区分普通访问与手机访问 ?

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

PHP检测代码: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= 'http://www.yuzhiguo.com/wap';

}

ASP检测代码:HTTP_ACCEPT=Request.ServerVariables("HTTP_ACCEPT")                 '获取浏览器信息

HTTP_USER_AGENT=LCase(Request.ServerVariables("HTTP_USER_AGENT"))  '获取AGENT

HTTP_X_WAP_PROFILE=Request.ServerVariables("HTTP_X_WAP_PROFILE")   'WAP特定信息 品牌机自带浏览器都会有

HTTP_UA_OS=Request.ServerVariables("HTTP_UA_OS")                   '手机系统 电脑为空

HTTP_VIA=LCase(Request.ServerVariables("HTTP_VIA"))                '网关信息

Dim WapStr

WAPstr=False

If ubound(split(HTTP_ACCEPT,"vnd.wap"))>0 Then WAPstr=True

If HTTP_USER_AGENT="" Then  WAPstr=True

If HTTP_X_WAP_PROFILE<>"" Then  WAPstr=True

If HTTP_UA_OS<>"" Then  WAPstr=True

IF ubound(split(HTTP_VIA,"wap"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"netfront"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"iphone"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"opera mini"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"ucweb"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"windows ce"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"symbianos"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"java"))>0 Then  WAPstr=True

IF ubound(split(HTTP_USER_AGENT,"android"))>0 Then  WAPstr=True

If WAPstr=True Then

'手机网址

response.redirect "http://www.yuzhiguo.com/wap"

else

'电脑网址

response.redirect "http://www.yuzhiguo.com"

End if

Js代码:

try {

var urlhash = window.location.hash;

if (!urlhash.match("fromapp"))

{

if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))

{

window.location="http://www.yuzhiguo.com/wap";

}

}

}

catch(err)

{

}

239e89a671345c2cd91ee50d442757e4.png

发表评论

您的IP:123.8.253.73,来自:河南省漯河市

nopic.jpg%0D%0A%09%09%0D%0A%20%20%20%20%20%20%20%20

1.0513info8

: 支持博主

2012/11/29 12:37:56

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值