Reputation: 988
I would like to open a link using Google Chrome (not another browser) from my Cordova application. I tried several solutions but nothing works.
First, I tried to create a link to googlechrome://
(using a HTML <a>
tag). It opens Google Chrome, but I can't choose what URL to open.
Then, I tried to create a link to intent://my.url.com/#Intent;scheme=https;package=com.android.chrome;end
. This link works when I open it from a browser (like Firefox or Google Chrome), but it doesn't work when I open it from my Cordova app.
I also tried to use the cordova-webintent plugin, like that :
window.plugins.webintent.startActivity(
{
action: window.plugins.webintent.ACTION_VIEW,
url: 'intent://my.url.com/#Intent;scheme=https;package=com.android.chrome;end'
},
function() {
alert(url);
},
function(){
alert('Failed to open URL via Android Intent');
}
);
But I get a "Failed to open URL via Android Intent" error.
What should I do ?
PS : I wrote <allow-intent href="*" />
in my config.xml file.
Upvotes: 3
Views: 7121
Reputation: 988
I finally found the solution. I just had to create a link like this one :
<a href="googlechrome://navigate?url=https://my.url.com/"></a>
Upvotes: 1
Reputation: 3853
You can use cordova-plugin-inappbrowser with _system
as target:
cordova.InAppBrowser.open('http://stackoverflow.com', '_system', 'location=yes');
Or you can use cordova-plugin-webintent2 (don't know if this is the same you are using), like this:
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: "googlechrome://navigate?url=http://www.stackoverflow.com"
},
function() {},
function() {
alert('Failed to open URL via Android Intent.');
console.log("Failed to open URL via Android Intent.")
});
The url must start with http or https, it does not allow relative urls.
Upvotes: 3