在做网页的时候,有些页面有pc版跟wap版。那么在同一个页面的情况下怎样做到在电脑端直接转手机端,或者用手机端访问PC网址直接跳转wap网址。这边就需要做跳转处理:
(function(){
var ua = navigator.userAgent.toLowerCase();
var bIsIpad = ua.match(/ipad/i) == “ipad”;
var bIsIphoneOs = ua.match(/iphone os/i) == “iphone os”;
var bIsAndroid = ua.match(/android/i) == “android”;
var bIsWM=ua.match(/windows mobile/i)==“windows mobile”;
var host = “你的手机端网址”;
var pathname = window.location.pathname;
if(bIsIpad||bIsIphoneOs||bIsAndroid||bIsWM){
window.location.href =host + pathname;
}
})();