Last active
March 11, 2018 13:18
-
-
Save cssmagic/6238619 to your computer and use it in GitHub Desktop.
让手机用户自动跳转到移动版网站。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ua = _ua || {}; | |
_ua.str = navigator.userAgent.toLowerCase(); | |
_ua.isAndroid = _ua.str.indexOf('android') > -1 && _ua.str.indexOf('mobile') > -1; | |
_ua.isIPhone = /\(i(?:phone|pod);/.test(_ua.str); | |
if (_ua.isAndroid || _ua.isIPhone) { | |
location.href = 'http://m.example.com/'; | |
} |
为什么在建议在服务端做呢?
在服务端跳转对蜘蛛更友好,效率也更高
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一段简单的脚本,可以把手机用户(Android / iPhone / iPod)重定向到移动版网站。不过在正常情况下,建议你在服务器端做类似的工作。