根据userAgent实现跳转到移动或者pc页面代码
分类:实例代码
可以根据浏览器的userAgent的信息来实现选择移动端还是pc端页面的跳转功能。
代码实例如下:
var ua = window.navigator.userAgent; if (ua.match(/mobile/i)) { location.href = 'http://m.baidu.com'; } else { location.href = 'http://www.baidu.com'; }
根据userAgent实现跳转到移动或者pc页面代码,这样的场景在实际项目中还是用的比较多的,关于根据userAgent实现跳转到移动或者pc页面代码就介绍到这了。
根据userAgent实现跳转到移动或者pc页面代码属于前端实例代码,有关更多实例代码大家可以查看。
