Home > Uncategorized > Open link in external browser using Phonegap Webworks for Blackberry

Open link in external browser using Phonegap Webworks for Blackberry

If you are developing apps for BlackBerry using PhoneGap / Webworks for Blackberry, then you have probably noticed that  if you add a url to an external website, such as <a href=”http://www.google.com”>Google</a&gt;, then the destination website gets loaded within the frame of the app, giving a poor user experience, and no way to return to the app, apart from closing the app.

The solution is not obvious, since you have to use Webworks API (which is not cross-platform, it’s BlackBerry only).

use the following code when itializing JQuery

$(‘a[target=”_blank”]’).live( ‘click’, function()
{
if ( window.blackberry )
{
alert( ‘Loading website: ‘ + $(this).attr( ‘href’ ) );
var args = new blackberry.invoke.BrowserArguments( $(this).attr( ‘href’ ));
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
return false;
}
return true;
})

Then IMPORTANTLY add the following lines to the config.xml

<feature id=”blackberry.app” required=”true” version=”1.0.0.0″/>

<feature id=”blackberry.invoke”/>
<feature id=”blackberry.invoke.BrowserArguments” />

<access uri =”*”/>

I have heard that this invocation mechanism may change for BlackBerry 10 / Playbook, which I am going to test soon.

Advertisements
Categories: Uncategorized
  1. November 7, 2012 at 10:21 pm

    I’ve tested this code on a Playbook, and it works fine.

  2. Luis
    March 24, 2014 at 6:30 pm

    It still working? It doesnt for me, where must add the code? I have the features in cobfig.xml but the code is not working, help me please. Im working with bbww, phobegap 2.9.1 and jquerymobile.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: