【问题标题】:One button -- 3 App stores -- how to redirect the user to the appropriate appstore?一键——3个应用商店——如何将用户重定向到合适的应用商店?
【发布时间】:2014-10-02 08:15:33
【问题描述】:

我想创建一个简单的按钮,根据他们正在运行的移动操作系统(ios、android 或 wp8)将移动用户重定向到适当的应用商店链接 - 或者如果不在移动设备上,则提供发送包含以下内容的电子邮件适当的链接...有什么想法吗?

【问题讨论】:

    标签: javascript android jquery ios windows-phone-8


    【解决方案1】:

    嗯...这实际上非常简单。首先,您必须通过用户代理字符串检测用户当前正在使用的设备。然后使用jQuery简单地正确设置锚元素的href属性。下面的代码说明了。

    var operatingSystem, userAgentString = navigator.userAgent;
    var link = $("#store");
    
    if (userAgentString.indexOf("iPhone") > -1 || userAgentString.indexOf("iPod") > -1 || userAgentString.indexOf("iPad") > -1) {
        operatingSystem = "iOS";
        link.attr("href", "http://store.apple.com/us/browse/app");
    } else if (/Android/.test(userAgentString)) {
        operatingSystem = "Android";
        link.attr("href", "https://play.google.com/store/apps?hl=en");
    } else if (/Windows Phone/.test(userAgentString)) {
        operatingSystem = "Windows Phone";
        link.attr("href", "http://www.windowsphone.com/en-us/store");
    }
    

    http://jsfiddle.net/5g0zqm0s/

    【讨论】:

    • 非常感谢。我完全忘记了我已经发布了这个问题(处理其他事情)然后开始想知道如何完成这项任务并记住....我没有忽略你!谢谢!! :D
    • 您必须先检查 Windows Phone,因为最近的 Windows Phone 用户代理包含“Android”和“iPhone”,例如Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Lumia 640 LTE) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
    【解决方案2】:

    检查用户代理以确定正在运行的操作系统并根据结果路由链接适当。

    【讨论】:

      【解决方案3】:

      使用 php,您可以检测用户在哪个移动设备上。有几个插件可以做到这一点。然后,您可以相应地回显链接的 href。对不起,不能评论。花了太多的赏金!

      【讨论】:

        猜你喜欢
        • 2016-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-24
        • 2014-04-06
        • 1970-01-01
        相关资源
        最近更新 更多