Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 9
Registered: ‎03-10-2012
My Device: BlackBerry Playbook
My Carrier: N/A

BlackBerry PlayBook (& Phones?) opening links in browser instead of within app. [SNIPPET]

[ Edited ]

Hey, I had some problems trying to make links open within the browser rather than in the app itself. Here's how I solved the problem.

 


var openURL = function(obj){
     var href = $(obj).attr('href');
     var args = new blackberry.invoke.BrowserArguments(href);
     blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
};


var linkListener = function(){
     $('a').click(function(){
         openURL(this);
         return false;
     });
};
linkListener();

If you generate <a> tags with Javascript then call linkListener() after you create the element. 

Regular Contributor
Posts: 81
Registered: ‎03-09-2012
My Device: PlayBook & Bold 9780
My Carrier: n/a

Re: BlackBerry PlayBook (& Phones?) opening links in browser instead of within app. [SNIPPET]

[ Edited ]

That's fine and dandy, but this way you cannot run the same html5 source in another webkit browser such as Chrome. However that can be fixed as follows:

 

/*
* Open a URL in a new window, implementation depends on device.
*/
function openUrl(myUrl) {
if ('blackberry' in window) {
var args = new blackberry.invoke.BrowserArguments(myUrl);
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
} else {
window.open(myUrl, "_new");
}
}

 Also don't forget to include the feature access in your config.xml:

 

   <access uri="http://www.mydomain.com" subdomains="false">
	   <feature id="blackberry.invoke" required="true" version="1.0.0"/>
   </access>

 

 

New Developer
Posts: 9
Registered: ‎03-10-2012
My Device: BlackBerry Playbook
My Carrier: N/A

Re: BlackBerry PlayBook (& Phones?) opening links in browser instead of within app. [SNIPPET]

The code above was more for WebWorks apps, not really cross platform.l