现在手头上有两套较老的系统,一个是手机端网站,一个是PC端网站,对于用户而言,需要输入一个通用通过域名,就可以自动识别手机端与PC端,如何做到的呢?非法简单,只要用JS实现即可。
下面对三个域名为例,www.lixh.cn 实现页面的跳转,pc.lixh.cn为PC电脑端,m.lixh.cn为手机端。假设PC端与手机端已经配置完成,我们只要在www.lixh.cn域名对应的网站空间中建立一个index.html文件,并将如下代码复制进去即可(域名大家可以根据自己的情况进行修改,还有就是一个网站可以配置多个网站,如果不会可以参看我博客的其他文章)。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>根据终端转向相应页面</title>
</head>
<body>
<script type="text/javascript">
function browserRedirect() {
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) {
window.location.href= 'http://m.lixh.com';
} else {
window.location= 'http://pc.lixh.com';
}
}
browserRedirect();
</script>
</body>
</html>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。