手机浏览网站自动跳转到wap页面的代码
分类:网页设计 Tags: 手机网站 wap 评论:1 浏览:7407 最近更新时间:2015/3/16 11:24:42
手机访问网站域名时如果实现自动跳转到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代码:
<script type="text/javascript"> 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) { }</script>
本文地址:/523/
-
• 通过css代码做Table表格隔行变色效果
• Div+CSS网页布局入门实例教程三(图)
• 合格的网页设计师应该具有那些素质?
• 网页中连续循环滚动的制作代码
• 合理的网页设计具有哪些特征
• 如何将文本输入框与文本不对齐,input对齐同一行文字
• iis如何支持.webp图片格式访问
• 自定义网页鼠标样式代码,让自己的网页更个性
• 用CSS做的个性alt跟随title效果
• ASP生成农历日期程序代码,含年月日、星期、天干、地支、属相