Opening links in phonegap

0
Hi, we're using the CKEditor widget to allow end users to write news articles. The CKEditor widget allows you to enable the links toolbar in the document, so the end user can easily insert links to other websites etc. This feature works fine for the desktop page, but on phonegap the url will replace the mendix webview. Do you have any suggestions on how to handle links in phonegap?
asked
3 answers
0

To capture all external links in your application and open them in a separate browsertab - or on mobile in your browser app - you can use this script. It's basically the same as suggested in the SO thread, but based on dojo instead of jquery.

require(["dojo/dom-attr", "dojo/on", "dojo/domReady!"], function(domAttr, on) {
if(!window.device) {
    window.device = { platform: 'browser' };
}
if(!window.extLinksHandler) {   
    on(document, 'a[href^="http"]:click', function(e) {
        e.preventDefault();
        var url = domAttr.get(e.target, 'href');
        if(device.platform.toLowerCase() === 'android' || device.platform.toLowerCase() === 'ios') {
            window.open(url, '_system');
        } else
            window.open(url, '_blank');
    });
    window.extLinksHandler = true;
}

});

answered
0

To be honest I'm not too familiar with the CKEditor. Normally, you solve this by setting the target of the link to _blank, this will tell the operating system to open it in a new browser instead of the existing app.

answered
0

The top answer in this SO thread is the standard PhoneGap solution. I'm guessing you could modify CKEditor to create HTML like this for links instead of a normal link. The same solution should also work on desktop browsers, as you're just using the JavaScript window.open function.

answered