js自动判断客户端系统
这里用微信读书举例,以下代码如果访问者使用安卓手机会跳转到应用宝的微信读书下载页面:https://a.app.qq.com/o/simple.jsp?pkgname=com.tencent.weread
;如果使用苹果手机或者ipad会跳转到appstore中微信读书下载页面:https://itunes.apple.com/cn/app/wei-xin-du-shu/id952059546
。
js自动判断系统演示代码
纯js无需jquery支持
1 | <script type="text/javascript"> |
2 | var browser = { |
3 | versions: function () { |
4 | var u = navigator.userAgent, app = navigator.appVersion; |
5 | return { //移动终端浏览器版本信息 |
6 | ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 |
7 | android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 |
8 | iPhone: u.indexOf('iPhone') > -1, //是否为iPhone |
9 | iPad: u.indexOf('iPad') > -1, //是否iPad |
10 | }; |
11 | }(), |
12 | } |
13 | if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) { |
14 | window.location.href = "https://itunes.apple.com/cn/app/wei-xin-du-shu/id952059546"; |
15 | } |
16 | if (browser.versions.android) { |
17 | window.location.href = "https://a.app.qq.com/o/simple.jsp?pkgname=com.tencent.weread"; |
18 | } |
19 | </script> |
代码出处不详(忘记了),作者可以以留言认领(文中将注明来源)。
本页旧文
2012-06-27 果壳网Guokr.com 招聘前端开发工程师 view 6,888