通过 javascript 重定向从 android 浏览器打开应用程序的 google play 详细信息页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10204879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open google play details page for an app via javascript redirect from android browser
提问by daniel.auener
I want my website to redirect to a specific app in the Google Play Market if it is opened on an android device. I followed the instructions on http://developer.android.com/guide/publishing/publishing.html:
如果我的网站在 Android 设备上打开,我希望我的网站重定向到 Google Play Market 中的特定应用程序。我按照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>".
Works great with a link the user is actively clicking on:
与用户主动点击的链接配合使用效果很好:
<a href="http://play.google.com/store/apps/details?id=<package_name>">Download app</a>
But if I am detecting the device with javascript and trying to redirect the browser automatically changes the http://... to https://... and the user is redirected to the Google Play website instead of the Google Play app on the phone.
但是,如果我使用 javascript 检测设备并尝试重定向浏览器会自动将 http://... 更改为 https://... 并且用户将被重定向到 Google Play 网站而不是 Google Play 应用程序电话。
if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
if(confirm("Download app?")) {
window.location.href= "http://play.google.com/store/apps/details?id=<package_name>";
}
}
Is there any way to change this behavior, my test device is a Samsung Galaxy with android 2.3.3?
有什么办法可以改变这种行为,我的测试设备是带有 android 2.3.3 的三星 Galaxy?
回答by TerryProbert
This seems to work. The redirect opens the Google Play app while using the default browser, but translates the link to https:// play.google... when using chrome
这似乎有效。重定向会在使用默认浏览器时打开 Google Play 应用程序,但在使用 chrome 时会将链接转换为 https:// play.google...
if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
if(confirm("Download app?")) {
window.location.href= "market://details?id=<packagename>";
}
}
回答by Yossi Neiman
If you want to redirectto Google Play apptry doing it from the server.
如果您想重定向到Google Play 应用程序,请尝试从服务器执行此操作。
Client side attempts will not work.
客户端尝试将不起作用。
PHP example
PHP 示例
header("Location: market://details?id=com.your.app");
回答by Fixticks
If the accepted answer does not work or fails to open in Chrome with this error
如果接受的答案不起作用或无法在 Chrome 中打开并出现此错误
ERROR: ERR_UNKNOWN_URL_SCHEME
错误:ERR_UNKNOWN_URL_SCHEME
Change the window.location.href to window.location like this
像这样将 window.location.href 更改为 window.location
if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
if(confirm("Download app?")) {
window.location= "market://details?id=<packagename>";
}
}