惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 小龟爬爬

Visual Studio 2010 Professional MSDN版已出,非试用版 基于OAI协议元数据收割的.NET资源 关于LNK2001错误的一些总结 C++预处理命令""和<>的区别 - 小龟爬爬 - 博客园 Mozilla Firefox 3.0 官方下载(附下载日证书截图) 在 Windows Server 2008 上安装 IIS 7.0 Visual Studio SharePoint工作流功能具有特定的安装要求 Mcafee官方卸载工具 磁盘变RAW文件系统解决办法 GridView列数字、货币和日期的显示格式 - 小龟爬爬 - 博客园 .net2.0 GRIDVIEW弹出删除对话框 - 小龟爬爬 - 博客园 FCKeditor出现&quot;this connector is disabled Please check the&quot;editor/filemanager/connectors/aspx/config.aspx&quot;错误的解决办法 FCKeditor出现&quot;XML request error: Internal Server Error(500)&quot;错误的解决办法 经常使用的判断string是否为数字的函数 .NET2.0学习笔记(一)访问母版页中的控件 string 与 stringBuilder Access 至少一个参数没有被指定值 解决方法 JS判断字符串格式是否合法 - 小龟爬爬 JavaScript使用技巧精萃
利用浏览器 UA 信息解决多平台手机应用下载问题
小龟爬爬 · 2012-09-24 · via 博客园 - 小龟爬爬

1、问题:

公司合作伙伴提出,希望公司提供一个二维码,实现用户在扫描二维码以后 android 直接下载对应 apk 文件,而 ios 平台能直接跳转至 itunes 软件显示页。

2、初步方案:

合作伙伴的要求其实是要求一个下载地址,可以提供多平台手机应用的下载。我们可以在二维码里面放置一个静态页面,而在这个静态页面可以根据用户的 UA 信息,进行不同的操作。

1)获取用户的 UA 信息;

2)判断 用户为 ios 或者 mac 系统时,跳转至软件对应 itunes 页面;

3)其他情况直接下载对应 apk 文件。

代码如下:

<script type="text/javascript">
    var android = 'http://q.kuaipai.cn/quickpai.apk';
    var ios = 'http://itunes.apple.com/cn/app/id519048827?mt=8';
    var ua = navigator.userAgent.toLowerCase();  
    var isandroid=1;
    if (ua.indexOf('iphone') > 0) {
 isandroid = 0;
    } else if (ua.indexOf('mac os') > 0) {
 isandroid = 0;
    }           
    if (isandroid == 1) {
 window.location.href= android;
    } else {
 window.location.href= ios;
    }
</script> 

3、升级方案:

初步解决方案只对 UA 进行了初步的判断,整理逻辑也不够正确。如果用户是在 mac 环境中使用 android 手机,或者是结合 windows 系统使用 iphone ,都会出现不符合用户期望结果的发生。

1)获取用户的 UA 信息;

2)判断 用户为 ios 系统时,跳转至软件对应 itunes 页面;

3)判断 用户为 android 系统时,直接下载 apk 文件;

4)其他情况不做跳转,在静态页面上同时显示软件对应 itunes 页面连接和 apk 软件下载地址供用户自己选择。

代码如下:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>北京灵动快拍信息技术有限公司</title>
</head>
<body>
<script type="text/javascript">
    var android_down_url = 'http://q.kuaipai.cn/quickpai.apk';
    var ios_down_url = 'http://itunes.apple.com/cn/app/id519048827?mt=8';

    var ua = navigator.userAgent.toLowerCase();  
    if (ua.indexOf('iphone') > 0) {                        //需对所有 ios 系统 UA 信息进行判断
        window.location.href = ios_down_url;
    } else if (ua.indexOf('android') > 0) {                //需对所有 android 系统 UA 信息进行判断
        window.location.href = android_down_url;
    } 
</script>
<href="http://q.kuaipai.cn/quickpai.apk">点击下载“快拍二维码” android 版</a>
<href="http://itunes.apple.com/cn/app/id519048827?mt=8">点击下载“快拍二维码” iphone 版</a>
</body>
</html>

四平台首发:
个人博客 http://xiaogui.org/one-page-down-the-app.html
CSDN博客 http://blog.csdn.net/xgpapa/article/details/8011622
博客园  http://www.cnblogs.com/xgpapa/archive/2012/09/24/2699623.html
ItEye博客  http://xgpapa.iteye.com/blog/1684090