In App Browser
Launches in app Browser
Repo: https://github.com/apache/cordova-plugin-inappbrowser
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-inappbrowser $ npm install --save @ionic-native/in-app-browser@4
- Add this plugin to your app's module
Supported platforms
- AmazonFire OS
- Android
- Browser
- iOS
- macOS
- Windows
Usage
import { InAppBrowser } from '@ionic-native/in-app-browser';
constructor(private iab: InAppBrowser) { }
...
const browser = this.iab.create('https://ionicframework.com/');
browser.executeScript(...);
browser.insertCSS(...);
browser.on('loadstop').subscribe(event => {
browser.insertCSS({ code: "body{color: red;" });
});
browser.close();
Instance Members
create(url, target, options)
Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
Param | Type | Details |
---|---|---|
url |
string
|
The URL to load. |
target |
string
|
The target in which to load the URL, an optional parameter that defaults to _self. |
options |
string
|
Options for the InAppBrowser. Optional, defaulting to: location=yes. The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. |
Returns: InAppBrowserObject
InAppBrowserObject
Instance Members
show()
Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible.
close()
Closes the InAppBrowser window.
hide()
Hides an InAppBrowser window that is currently shown. Calling this has no effect if the InAppBrowser was already hidden.
executeScript(script)
Injects JavaScript code into the InAppBrowser window.
Param | Type | Details |
---|---|---|
script |
Object
|
Details of the script to run, specifying either a file or code key. |
Returns: Promise<any>
insertCSS(css)
Injects CSS into the InAppBrowser window.
Param | Type | Details |
---|---|---|
css |
Object
|
Details of the script to run, specifying either a file or code key. |
Returns: Promise<any>
on(event)
A method that allows you to listen to events happening in the browser.
Param | Type | Details |
---|---|---|
event |
string
|
Name of the event |
Returns: Observable<InAppBrowserEvent>
Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
InAppBrowserEvent
Param | Type | Details |
---|---|---|
type |
string
|
the eventname, either loadstart, loadstop, loaderror, or exit. |
url |
string
|
the URL that was loaded. |
code |
number
|
the error code, only in the case of loaderror. |
message |
string
|
the error message, only in the case of loaderror. |
InAppBrowserOptions
Param | Type | Details |
---|---|---|
location |
'yes' | 'no'
|
Set to yes or no to turn the InAppBrowser's location bar on or off. (optional) |
hidden |
'yes' | 'no'
|
(optional) |
clearcache |
'yes'
|
Set to yes to have the browser's cookie cache cleared before the new window is opened. (optional) |
clearsessioncache |
'yes'
|
(optional) |
closebuttoncaption |
string
|
(optional) |
closebuttoncolor |
string
|
(optional) |
zoom |
'yes' | 'no'
|
(Android Only) Set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes. (optional) |
hardwareback |
'yes' | 'no'
|
(optional) |
mediaPlaybackRequiresUserAction |
'yes' | 'no'
|
Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no). (optional) |
hidenavigationbuttons |
'yes' | 'no'
|
(optional) |
hideurlbar |
'yes' | 'no'
|
(optional) |
navigationbuttoncolor |
string
|
(optional) |
toolbarcolor |
string
|
(optional) |
shouldPauseOnSuspend |
'yes' | 'no'
|
(Android Only) Set to yes to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues) (optional) |
footer |
'yes' | 'no'
|
(Android Only) Set to yes to show a close button in the footer similar to the iOS Done button. The close button will appear the same as for the header hence use closebuttoncaption and closebuttoncolor to set its properties (optional) |
footercolor |
string
|
(Android Only) Set to a valid hex color string, for example #00ff00 or #CC00ff00 (#aarrggbb), and it will change the footer color from default. Only has effect if user has footer set to yes (optional) |
disallowoverscroll |
'yes' | 'no'
|
(iOS Only) Set to yes or no (default is no). Turns on/off the UIWebViewBounce property. (optional) |
toolbar |
'yes' | 'no'
|
(iOS Only) Set to yes or no to turn the toolbar on or off for the InAppBrowser (defaults to yes) (optional) |
toolbartranslucent |
'yes' | 'no'
|
(iOS Only) Set to yes or no to make the toolbar translucent(semi-transparent) (defaults to yes). Only applicable if toolbar is not disabled. (optional) |
enableViewportScale |
'yes' | 'no'
|
(iOS Only) Set to yes or no to prevent viewport scaling through a meta tag (defaults to no). (optional) |
allowInlineMediaPlayback |
'yes' | 'no'
|
(optional) |
keyboardDisplayRequiresUserAction |
'yes' | 'no'
|
(iOS Only) Set to yes or no to open the keyboard when form elements receive focus via JavaScript's focus() call (defaults to yes). (optional) |
suppressesIncrementalRendering |
'yes' | 'no'
|
(iOS Only) Set to yes or no to wait until all new view content is received before being rendered (defaults to no). (optional) |
presentationstyle |
'pagesheet' | 'formsheet' | 'fullscreen'
|
(iOS Only) Set to pagesheet, formsheet or fullscreen to set the presentation style (defaults to fullscreen). (optional) |
transitionstyle |
'fliphorizontal' | 'crossdissolve' | 'coververtical'
|
(iOS Only) Set to fliphorizontal, crossdissolve or coververtical to set the transition style (defaults to coververtical). (optional) |
toolbarposition |
'top' | 'bottom'
|
(iOS Only) Set to top or bottom (default is bottom). Causes the toolbar to be at the top or bottom of the window. (optional) |
hidespinner |
'yes' | 'no'
|
(iOS Only) Set to yes or no to change the visibility of the loading indicator (defaults to no). (optional) |
fullscreen |
'yes'
|
(optional) |
useWideViewPort |
'yes' | 'no'
|
(Android Only) Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is no, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is yes and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to yes). (optional) |
beforeload |
'yes' | 'post' | 'get'
|
Allows for latest 'beforeload' feature of Cordova InAppBrowser to be registered as an option if using plugin's latest github master (1/4/2019) instead of npm. Post is currently not supported but will be. (optional) |