手机端、PC端分端,主要依赖于
navigator.userAgent.toLowerCase();
来判断当前访问的设备信息 再来匹配跳转的分端页面,具体方式如下:
<script type="text/javascript">
// 手机/pc 分端加载页面
var fileRediret=()=>{
// 获取设备信息
let userAgent = navigator.userAgent.toLowerCase();
// 正则表达式,判断设备类型
let device=/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile;
if(device.test(userAgent)){
// 跳转到对应的移动端页面
window.location.href="移动端.html";
}else{
//跳转到PC端页面
window.location.href="PC端.html"
}
}
// 执行
fileRediret();
</script>