我拥有以下代码,可让我在网站的桌面版和移动版之间进行切换,
<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera
Mini/i.test(navigator.userAgent) ) {
window.location = "http://m.mysite.co.uk";
}
</script>
Run Code Online (Sandbox Code Playgroud)
我最近意识到,所做的一切就是将所有人发送到该网站的主页。我仔细研究了一下,发现可以通过将上面的内容修改为,将特定页面重定向到移动版本,
<script type="text/javascript">
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location = "http://m.mysite.co.uk" + window.location.pathname;
}
</script>
Run Code Online (Sandbox Code Playgroud)
唯一的问题是URL路径末尾的斜杠导致URL无法识别。
有没有一种方法可以消除Javascript中的斜杠?
该站点位于旧的Windows 2003服务器上,因此它是IIS6,以防有人建议使用URL Rewrite模块。
感谢您提供的任何建议。