【发布时间】:2015-07-07 06:28:42
【问题描述】:
我希望,如果桌面用户访问我的网站,他们会被重定向到 example.com,而移动用户会被重定向到 m.example.com,我被告知使用此脚本:
<script>
if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) {
return window.location.assign("m.example.com");
} else {
return window.location.assign("example.com");
}
}
</script>
但是当我访问我的网站时,我得到的只是一个白屏。 这个脚本有问题吗?我需要另一个脚本来处理用户代理还是全部由上述脚本处理? 提前致谢。
【问题讨论】:
-
右括号过多?并将
http://添加到url?
标签: javascript redirect mobile desktop