最近在写官网 官网需要的是自适应的网页 但是PC和移动端的页面是不一样的 所以做了两套 PC的一套 手机的一套 项目准备上线了 既然做了两套 肯定是要手机端访问手机的页面 PC访问PC的页面 怎么办呢 用js来判断一下
在PC端的首页 头部 加上这句代码就可以啦 当你是移动设备访问 他自己会进行跳转
<script type="text/javascript">
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location.href = "http://127.0.0.1:8848/stu/test/moblie_Index.html";
}
</script>
测试例子
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
window.location.href = "https://www.baidu.com/";
} else {
window.location.href = "http://news.baidu.com/";
}

本文介绍了一种通过JavaScript实现自适应网页跳转的方法,确保移动设备访问移动端页面,PC端访问PC端页面,提供了具体代码示例。

221

被折叠的 条评论
为什么被折叠?



