user2331670
user2331670

Reputation: 335

Open link in external browser from blackberry10 with cordova

I am trying to open a link in the native browser or other external browser from my blackberry10 app, but I can only get it to open an in app browser. Please help me.

Upvotes: 0

Views: 468

Answers (1)

Luca S.
Luca S.

Reputation: 738

It seems that you are using the org.apache.cordova.inappbrowser plugin which is cross compatible but the default action is to open a new page in the childBrowser window. If you want to open it in the system browser you have two options:

OPTION 1: use the "_system" target in your call.

Your code will look like this

var ref = window.open('http://www.google.com', '_system');

OPTION 2: use the BlackBerry specific "invoke" api. In order to do so you need to first install the invoke plugin

cordova plugin add com.blackberry.invoke

Now you can have a function that (using the org.apache.cordova.device plugin) looks like this:

function openBlackBerryBrowser(url) {

    function onInvokeSuccess() {
        alert("Invocation successful!");
    }

    function onInvokeError(error) {
       alert("Invocation failed, error: " + error);
    }

    blackberry.invoke.invoke({
        target: "sys.browser",
        uri: url
    }, onInvokeSuccess, onInvokeError);
}

if(window.device.platform.toLowerCase().indexOf('blackberry') > -1) {
    openBlackBerryBrowser('http://www.google.com');
} else {
    var ref = window.open('http://www.google.com', '_system');
}

if you notice I'm setting the target attribute to "sys.browser" which is the default system browser. If the user has different browsers installed you could just specify something different like "com.myapp.mybrowser".

Upvotes: 2

Related Questions