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>, 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.
I’ve tested this code on a Playbook, and it works fine.
LikeLike
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.
LikeLike