Search code examples
onsen-ui

I need to launch an external website in Onsen Ui


I need to launch to launch an external url / website in Onsen Ui without leaving the app. I can use an iframe I guess between the ons-page tags where I need it but not very reliable perhaps.

Its my first Onsen Ui project.

Jimmy


Solution

  • Simply using the method below on OnsenUI

    <a href="www.example.com">Link</a>
    

    will destroy and replace the whole app (web view) with external HTML resources.


    Solution: so you may need the helps of cordova-plugin-inappbrowser plugin.

    In your case, launch an external url / website in Onsen Ui without leaving the app, you need "_self" or "_blank" ("_blank" is used for example codes below)

    // opts is optional depend on your requirements
    var opts = 'location=yes';
    var ref = cordova.InAppBrowser.open('http://www.example.com', '_blank', opts);
    

    or you can use ngCordova's $cordovaInAppBrowser

    angular.module('app')
        .controller('ctrl', ['$cordovaInAppBrowser', function($cordovaInAppBrowser) {
             var opts = {location: 'yes'};
             $cordovaInAppBrowser.open('http://www.example.com', '_blank', opts);
         }]);