自动适配跳转电脑PC端和手机WAP端

//首先获取浏览器所在系统平台对象
let sUserAgent = navigator.userAgent.toLowerCase();

//用正则滤出平台名称,如符合以下条件则跳转移动端,并作跳转
if (/ipad|iphone|midp|webKit|rv:1.2.3.4|ucweb|android|windows ce|windows mobile!/.test(sUserAgent)) 
{
    //转wap端        
    window.location.href=./wap.html’;
}else{
    //转pc端        
    window.location.href=./pc.html’;
}

部分内容来自其他搏客,如有写得不对的地方,恳请指正,谢谢!

你可能感兴趣的:(笔记)