最近公司领导想让我把官网做成兼容移动端的,可是之前的项目虽然直兼容pc端,可是感觉样式和效果都不错,领导也希望把pc端保留,不要大的改动。于是想了想,有了一个方法。打开页面的时候判断设备是pc还是移动端。之后在分别调整链接,打开页面,这样我就这样做一套移动端的页面就ok了。哈哈,这样开发周期也可缩短了。
代码
<script>
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='pc段页面入口.html';
}else{
window.location.href='移动段页面入口.html';
}
}
browserRedirect();
</script>