春哥分享一下手机访问实现自动跳转的代码

最近帮客户开发手机版站点的时候,用到一个自动跳转到手机版的代码,今天春哥就把自己写的判断手机自动跳转的代码分享给大家,希望以后大家能够用到。春哥采用的是JS判断,一个JS完全搞定,当然方法多种多样。

<script>	
var noRedirect = location.search.split('noRedirect=')[1]
if ( ( noRedirect == null) || noRedirect.toString() != 'true' ){
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)
)
{
location.href = 'http://m.drplant.com.cn/';
}
}
</script>

就是这么简单的一段代码就可以完全搞定了。



来源:春哥技术博客,欢迎分享,转载请注明出处。(欢迎加春哥团队客服微信号:taike668)

本文地址:https://www.cgtblog.com/jishu/740.html
上一篇:分析三大VR游戏开发平台各自优势      下一篇:IE10浏览器smartscreen筛选器已经阻止