通过从安卓浏览器重定向的javascript打开应用程序的谷歌播放详细信息页面

Open google play details page for an app via javascript redirect from android browser

本文关键字:应用程序 谷歌 播放 详细信息 javascript 重定向 浏览器      更新时间:2023-09-26

我希望我的网站重定向到Google Play市场中的特定应用程序,如果它是在Android设备上打开的。我按照 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://...用户被重定向到谷歌播放网站,而不是手机上的谷歌播放应用。

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

有没有办法改变这种行为,我的测试设备是装有安卓 2.3.3 的三星银河?

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

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

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

客户端尝试将不起作用。

PHP示例

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

如果接受的答案不起作用或无法在 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>";
 }
}