您的位置:首页 > 移动开发

JS判断移动端和pc端加载不同页面

2017-06-13 15:13 369 查看
//pc端作判断
<script>
if (/mobile/i.test(navigator.userAgent)) {
window.location = 'http://xxxx/mobile.html'
}
</script>

//移动端端作判断
<script>
if(!/mobile/i.test(navigator.userAgent)){
window.location = 'http://xxxx/pc.html';
}
</script>

// 万能脚本,自动屏蔽 pc
window.addEventListener('DOMContentLoaded', function() {
if (!((/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i).test(navigator.userAgent))) {
document.documentElement.innerHTML = "<p>请使用手机打开此页面哦~</p>";
}
});


注意:放在meta标签后
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: