【问题标题】:Open google play details page for an app via javascript redirect from android browser通过 android 浏览器中的 javascript 重定向打开应用程序的 google play 详细信息页面
【发布时间】:2012-04-18 07:30:54
【问题描述】:

如果我的网站在 Android 设备上打开,我希望我的网站重定向到 Google Play 市场中的特定应用。我按照http://developer.android.com/guide/publishing/publishing.html上的说明进行操作:

"Display the details screen for a specific application: http://play.google.com/store/apps/details?id=<package_name>".

非常适合用户主动点击的链接:

<a href="http://play.google.com/store/apps/details?id=<package_name>">Download app</a>

但如果我使用 javascript 检测设备并尝试重定向浏览器会自动将 http://... 更改为 https://... 并且用户被重定向到 Google Play 网站而不是 Google在手机上玩应用。

if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
    if(confirm("Download app?")) {
        window.location.href= "http://play.google.com/store/apps/details?id=<package_name>";
    }
}

有什么办法可以改变这种行为,我的测试设备是三星 Galaxy,Android 2.3.3?

【问题讨论】:

  • 如何从javascript代码修改链接的href(&lt;a)而不是设置window.location.href?
  • 我尝试用 jquery 在链接上触发点击事件,但没有成功。你是什​​么意思“修改链接的href”?该链接本身正在工作,它是导致 android 浏览器将 http:// 替换为 https:// 的 javascript 重定向
  • 只是想知道,您使用的是默认浏览器还是谷歌浏览器测试版?我将您的 javascript sn-p 添加到测试页面 - 在我的 Galaxy Nexus 4.0.2 上使用默认浏览器,它可以正常工作。但是使用谷歌浏览器时,我没有获得“使用完成操作”选项,它只是将我带到网站 - 仍在查看它

标签: javascript android redirect google-play


【解决方案1】:

这似乎有效。重定向会在使用默认浏览器时打开 Google Play 应用,但在使用 chrome 时会将链接转换为 https://play.google...

if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
    if(confirm("Download app?")) {
        window.location.href= "market://details?id=<packagename>";
    }
}

【讨论】:

    【解决方案2】:

    如果您想重定向Google Play 应用,请尝试从服务器执行此操作。

    客户端尝试将不起作用。

    PHP 示例

        header("Location: market://details?id=com.your.app");
    

    【讨论】:

      【解决方案3】:

      如果接受的答案不起作用或无法在 Chrome 中打开并出现此错误

      错误:ERR_UNKNOWN_URL_SCHEME

      像这样将 window.location.href 更改为 window.location

      if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
       if(confirm("Download app?")) {
          window.location= "market://details?id=<packagename>";
       }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多