IBM Worklight - How can I display the content a URL refers to, without losing app context?

142 Views Asked by At

When writing a Worklight app it is verboten to change the URL of the DOM in which the application is running. This makes sense as a hypertext move to another URL will obliterate the state of the app.

On occasion however, in my app I receive a URL for a news article and the user wishes to read it. Displaying the new content in an iFrame would start to address the requirement, but then I need navigation controls, etc. and it starts to feel like I am reinventing a wheel.

Does Worklight, or one of the mobile JS frameworks provide a "browser in browser" experience that I need here?

1

There are 1 best solutions below

0
On BEST ANSWER

Worklight utilizes Cordova. Cordova makes it possible to display just what you wanted, a "browser in a browser" - InAppBrowser.

The InAppBrowser is a web browser view that displays when calling window.open(), or when opening a link formed as <a target="_blank">.

Try that.

No setup is required as the InAppBrowser plug-in is already part of the Worklight project (this may differ depending on your Worklight version; If you are using 6.x you're OK).

All you need to do is to call up the URL. For example, in yourProject\apps\yourApp\common\main.js:

function wlCommonInit() {
    window.open('http://apache.org', '_blank', 'location=yes');
}


Once the app initializes it will open the InAppBrowser:

enter image description here

And once tapping the Done button, you're back in the app.

You can of course not specify the location attribute so the navigation bar won't display. In that case, in order to go back to the app the user will need to tap the Back button:

enter image description here