Source Freeze

  • Home
  • iOS
  • Swift
  • Cross-Platform
  • About
  • Contact
Home » Cordova InAppBrowser Plugin Example using ionic framework

Cordova InAppBrowser Plugin Example using ionic framework

October 15, 2015 by Source Freeze Leave a Comment

In the previous tutorial  i had written a post about how to use cordova device plugin, this post was about cordova inappbrowser plugin example using ionic framework and ngcordova.

the cordova inappbrowser plugin is used to launch the URL into external browser or external applications, this example will work on iOS and Android devices.

Next create the ionic cordova project using the below command lines.

ionic start InAppBrowser blank

cd InAppBrowser

Then add the android and iOS platforms using the below ionic commands.

ionic platform add android

ionic platform add ios

Note:

Remember you must have mac to build ios applications.

Adding Cordova InAppBrowser Plugin

Next we have add the apache cordova inappbrowser plugin using the below command line.

ionic plugin add cordova-plugin-inappbrowser

Now we have configured the application to use cordova inappbrowser plugin.

Then add the buttons for open the link into various types browser client in the ion-content tag. once added the button tags add the event using ng-click attribute and add ng-controller attribute in the ion-content as mentioned in the below.

<body ng-app="starter">
    <ion-header-bar class="bar-stable">
        <h1 class="title">InAppBrowser</h1>
    </ion-header-bar>
    <ion-content ng-controller="ExampleController" padding="true">
        <button class="button button-full button-assertive" ng-click="openInExternalBrowser()">
            Open In External Browser
        </button>
        <button class="button button-full button-assertive" ng-click="openInAppBrowser()">
            Open In App Browser
        </button>
         <button class="button button-full button-assertive" ng-click="openCordovaWebView()">
            Open In Cordova Webview
        </button>
    </ion-content>
</body>

InAppBrowser Function

cordova inappbrowser plugin provides a web browser view that displays when calling  cordova.InAppBrowser.open() or existing window.open().

_blank: It opens the URL in the in app browser
_self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
_system: Opens in the system’s web browser.
location=yes: It displays the full URL of the page in the InAppBrowser in a location bar, by the default location is set to no.

angular.module('starter', ['ionic'])

.controller("ExampleController", function ($scope) {

$scope.openInExternalBrowser = function()
{
 // Open in external browser
 window.open('http://google.com','_system','location=yes'); 
};

$scope.openInAppBrowser = function()
{
 // Open in app browser
 window.open('http://google.com','_blank'); 
};

$scope.openCordovaWebView = function()
{
 // Open cordova webview if the url is in the whitelist otherwise opens in app browser
 window.open('http://google.com','_self'); 
};

});

next we have to run the application using the below command lines. if you are running in emulator you can use emulate instead run.

ionic run ios

ionic run android

Then run the application the output will looks like below, and find the full source code for this application in this github link.

cordova inappbrowser plugin using ionic

Filed Under: cordova, Hybrid, ionic framework, phonegap

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to Generate random numbers in JavaScript
  • How to Scroll to an Element in a React Component?
  • How to get a Date without the Time in JavaScript
  • How to modify url without reloading the page using javascript
  • How to disable server side rendering in nextjs
  • How to get a file type from URL in JavaScript

Recent Posts

  • How to Generate random numbers in JavaScript
  • How to Scroll to an Element in a React Component?
  • How to get a Date without the Time in JavaScript
  • How to modify url without reloading the page using javascript
  • How to disable server side rendering in nextjs
  • How to get a file type from URL in JavaScript

Recent Comments

    Tags

    beginner colon cross-platform es6 function html ionic iOS javascript mobile application development nextjs objective-c swift switch ternary typescript uiwebview Visual Studio plugin web developer

    Copyright © 2025 Source Freeze