在PhoneGap中打开Play商店应用程序

时间:2015-03-31 21:59:14

标签: cordova

我设计了一个混合移动应用程序,有两个版本。为了将用户引导到另一个版本,我将其包含在HTML5源代码中

    <a href="market://details?id=com.kabam.ff7">

        <img id=offtomarket alt="Get it on Google Play"
            src="./img/android_app.png" />

    </a>

图像完美显示但未在Android设备上打开Play商店应用。为什么?

com.kabam.ff7就是一个例子。

我也试过这种方法

$("#offtomarket").click(    

 function(e) {  window.open('market://details?id=com.kabam.ff7'); 
                alert("offtomarketclicked"); 
              }               );

它仍然无效。我确实看到警报窗口 感谢

2 个答案:

答案 0 :(得分:3)

尝试替换它:

window.open('market://details?id=com.kabam.ff7'); 

有了这个:

window.location.replace('market://details?id=com.kabam.ff7');

答案 1 :(得分:3)

我找到了解决方案

安装此插件

https://github.com/xmartlabs/cordova-plugin-market

CLI -

cordova plugin add https://github.com/xmartlabs/cordova-plugin-market

然后在你的JavaScript中

cordova.plugins.market.open('com.kabam.ff7'); 

如果您使用jQuery并且有一个ID为mybutton的按钮

$("#mybutton").click(   function(e) {       

cordova.plugins.market.open('com.kabam.ff7');   } );

在CSS中加入以下CSS,使徽章看起来更完美

img
{
    width  : 100%;
    height : auto
}