Phonegap Open Link in Browser

phonegap open link in browser

As suggested in a similar question, use JavaScript to call window.open with the target argument set to _system, as per the InAppBrowser documentation:

<a href="#" onclick="window.open('http://www.kidzout.com', '_system'); return false;">www.kidzout.com</a>

This should work, though a better and more flexible solution would be to intercept all links' click events, and call window.open with arguments read from the link's attributes.

Remember you must install the InAppBrowser plugin for this to work:

cordova plugin add cordova-plugin-inappbrowser

phonegap open link in app browser does not work

I faced the same issue. But after struggling a lot this is what fixed my issue.

First remove and re-add the InAppBrowser plugin,

cordova plugin remove cordova-plugin-inappbrowser

cordova plugin add cordova-plugin-inappbrowser

Then add the following to your config.xml,

<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.InAppBrowser" />
</feature>

Remember by this time, InAppBrowser have to be in your plugins folder.

Then the anchor tags in your app should look like,

<a id="to-recover" href="#" onclick="cordova.InAppBrowser.open('https://www.google.com', '_system', 'location=yes');" >google</a>

Note: Due to a bug in Cordova Android 7.1.3, InAppBrowser doesn't work. Maybe that is the issue affecting you. So stick with either Cordova Android 7.1.2 or upgrade to 7.1.4

Reference:

Android Class Not Found

Plugin doesn't install correctly

You can specify the Cordova Android version while installing like this,

cordova platform add android@7.1.4

PhoneGap Build: how to open external url in device browser on Android?

It's not the answer when you want to keep using PhoneGap Build, but I solved the problem by setting up a development environment for Cordova (PhoneGap) on my machine and compiling the app locally. In Cordova 2.5.0 window.open('http://www.myurl.nl', '_system'); works perfect, it will open the link in the system's browser.

So my advice is to stop using PhoneGap Build and start compiling your app locally. Here's how to set up your development environment for Cordova >>

phonegap and cordova not opening link in app browser

First you need to initialize the plugin like so:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open = cordova.InAppBrowser.open;
}

This is taken from the https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/

_blank: Opens in the InAppBrowser.

_system: Opens in the system's web browser.

Therefor you need to change :

<a href="#" onclick="window.open('http://www.tutorialspoint.com/', '_system');">system</a><br/>

To this :

<a href="#" onclick="window.open('http://www.tutorialspoint.com/', '_blank', 'location=yes');">system</a><br/>

Phonegap 2.9.0 doesn't open external links in default browser

To have links in a Cordova/PhoneGap App open in the default browser of the device, you have to make sure that window.open(<url>, '_system'); will be used to access it. For this to actually work -maybe a bit counter-intuitively- you need to enable the ‘InAppBrowser’ plug-in.

In Cordova version 2.9.0 the ‘InAppBrowser’ plug-in is built-in and you only have to make sure it is not commented out in Cordova’s config.xml. From version 3.0.0 on you will have to install the plug-in by running this command from your project directory:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

From the Cordova documentation on how ‘InAppBrowser’ uses the second argument target of window.open() in its overriden implementation:

target: The target in which to load the URL, an optional parameter that defaults to _self. (String)

  • _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
  • _blank: Opens in the InAppBrowser.
  • _system: Opens in the system's web browser.

In order to separate concerns and to prevent me from forgetting to add an onclick attribute to every <a/> that I want to open in the default browser, I like to dynamically attach that behaviour via JavaScript. Below is an example using jQuery in which the behaviour will also be re-attached after reloading the involved HTML via XHR. And it will only be attached to external links, thus also preventing attaching it to mailto: links.

$('#idContentwrapper').on('click', '.colofon-text a', function(event) {
var href = $(this).attr('href');
if (typeof href !== 'undefined' &&
href.substr(0, 7) === 'http://')
{
event.preventDefault();
// Open in default browser App (on desktop: open in new window/tab)
window.open(this.href, '_system', 'location=no');
}
});

phonegap - open link in browser

This is how I got it working using Cordova 2.2 and jQuery mobile on Android

Javascript:

$('.link').live('tap', function() {
url = $(this).attr("rel");
loadURL(url);
});

function loadURL(url){
navigator.app.loadUrl(url, { openExternal:true });
return false;
}

html:

<a href='#' class='link' rel='http://www.someurl.com'>Go Somewhere</a>


Related Topics



Leave a reply



Submit