← Plugins / In-App Browser
This official Apache Cordova plugin opens a URL inside a separate, controllable web view that sits on top of your app — without leaving it. You get back a browser instance you can listen to, run scripts in, and close programmatically, which makes it ideal for OAuth flows, help pages and external links.
Add the plugin to your Cordova project from the command line:
cordova plugin add cordova-plugin-inappbrowser
Call cordova.InAppBrowser.open() after deviceready. It returns an InAppBrowser instance:
| Signature | Description |
|---|---|
cordova.InAppBrowser.open(url, target, options) | Opens url and returns a reference to the new browser window. |
The target argument decides where the URL loads:
| Target | Opens in |
|---|---|
_self | The Cordova web view if the URL is in the allow list, otherwise the in-app browser. |
_blank | The in-app browser (the default for most use cases). |
_system | The device's default system browser. |
The options argument is a comma-separated string of feature=value pairs, e.g. location=yes,toolbar=yes,hidden=no. Common options include location, toolbar, hidden, zoom (Android) and presentationstyle (iOS).
| Member | Description |
|---|---|
ref.close() | Close the browser window. |
ref.show() / ref.hide() | Show or hide a window that was opened with hidden=yes. |
ref.executeScript(details, cb) | Run JavaScript inside the loaded page. |
ref.insertCSS(details, cb) | Inject CSS into the loaded page. |
ref.addEventListener(event, cb) | Listen for loadstart, loadstop, loaderror, message or exit. |
ref.removeEventListener(event, cb) | Stop listening for an event. |
Open a page, react when it finishes loading, and close it from code:
function openHelp() {
var ref = cordova.InAppBrowser.open(
"https://dedrisframework.com/docs.html",
"_blank",
"location=yes,toolbar=yes"
);
ref.addEventListener("loadstop", function () {
console.log("Page loaded");
});
ref.addEventListener("exit", function () {
console.log("Browser closed");
});
}
_blank for in-app pages and _system to hand a link to the device browser.hidden=yes, wait for loadstop, then call show() to avoid showing a blank page.loadstart for your redirect URI and call close() once you've captured the token.