同一个网址,根据pc跟移动端,跳到对应页面

同一个网址,比如说访问。www.hnts001.com,pc端打开显示index.html.移动端打开显示wap.html.。这个是我项目路径。具体需要怎么实现呢?我需要具体代码。ps这两个都是静态页面。
前端可以实现的话因可能前端。要是后端做得话 我不是很了解

https://img2.mukewang.com/5c4820e20001ceb604400208.jpg

慕容森
浏览 639回答 1
1回答

jeck猫

index页面加这段代码<script>&nbsp; &nbsp; &nbsp; &nbsp; if( navigator.userAgent.match(/Android/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/webOS/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/iPhone/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/iPad/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/iPod/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/BlackBerry/i)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; || navigator.userAgent.match(/Windows Phone/i)&nbsp; &nbsp; &nbsp; &nbsp; ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.location.href="wap.html";&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript