WebViewer Cordova, Open Links in External Browser

85 views
Skip to first unread message

Matt Parizeau

unread,
Mar 5, 2014, 3:55:02 PM3/5/14
to pdfnet-w...@googlegroups.com
Q:

We have successfully integrated WebViewer into our app, however if we click a link then it is opened inside of our app and there isn't any way to return to the app.  Is it possible to open the link in the default browser?

A:

To get this to work, first you'll need to install the "InAppBrowser" plugin.  The name is a bit confusing but it will allow you to open links in the default browser when passing a certain parameter.  Details about the plugin are here, but basically you'll just need to run the command cordova plugin add org.apache.cordova.inappbrowser.

Next we'll have to make a couple changes to MobileReaderControl.html so that when window.open is called we'll inject the extra parameter '_system' which will open the link in the external browser.  First look for a script tag that has the code $(document).bind("mobileinit")..., and inside that same script tag add the following code:

document.addEventListener('deviceready', function() {
    var oldOpen = window.open;
    window.open = function(target) {
        return oldOpen(target, '_system');
    };
});

The last change is to add the following line, directly above <link rel="stylesheet" href="external/custom.css" />
<script src="../../cordova.js"></script>

This is the path to cordova.js if you followed the steps in WebViewer's cordova sample readme, so if you've changed the structure somewhat just make sure that the src correctly references cordova.js.
Reply all
Reply to author
Forward
0 new messages