cordova-plugin-inappbrowser

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

您可以在应用程序中显示有用的文章、视频和网络资源。用户可以查看网页,而无需离开您的应用程序。

要获得一些想法,请查看此页面底部的示例,或直接转到参考内容。

此插件提供一个网页浏览器视图,在调用cordova.InAppBrowser.open()时显示。

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');

window.open

cordova.InAppBrowser.open()函数被定义为window.open()函数的直接替换。现有的window.open()调用可以使用 InAppBrowser 窗口,方法是替换 window.open

window.open = cordova.InAppBrowser.open;

如果您以这种方式更改浏览器的window.open函数,它可能会产生意想不到的副作用(尤其是当此插件仅作为另一个插件的依赖项包含时)。

InAppBrowser 窗口的行为类似于标准网页浏览器,无法访问 Cordova API。因此,如果您需要加载第三方(不受信任)内容,而不是将其加载到主 Cordova webview 中,建议使用 InAppBrowser。InAppBrowser 不受白名单限制,也不受在系统浏览器中打开链接的限制。

InAppBrowser 默认情况下提供自己的 GUI 控件供用户使用(后退、前进、完成)。

安装

cordova plugin add cordova-plugin-inappbrowser

如果您希望应用程序中的所有页面加载都通过 InAppBrowser 进行,您只需在初始化期间挂钩window.open。例如

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
}

首选项

config.xml

  • InAppBrowserStatusBarStyle [仅限 iOS]: (字符串,选项 'lightcontent'、'darkcontent' 或 'default'。默认为 'default') 设置 iOS 的文本颜色样式。'lightcontent' 旨在用于深色背景。'darkcontent' 仅在 iOS 13 及更高版本中可用,旨在用于浅色背景。 ```xml

## cordova.InAppBrowser.open

Opens a URL in a new `InAppBrowser` instance, the current browser
instance, or the system browser.

    var ref = cordova.InAppBrowser.open(url, target, options);

- __ref__: Reference to the `InAppBrowser` window when the target is set to `'_blank'`. _(InAppBrowser)_

- __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters.

- __target__: The target in which to load the URL, an optional parameter that defaults to `_self`. _(String)_

    - `_self`: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the `InAppBrowser`.
    - `_blank`: Opens in the `InAppBrowser`.
    - `_system`: Opens in the system's web browser.

- __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_

    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.

    All platforms support:

    - __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.

    Android supports these additional options:

    - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
    - __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error).
    - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
    - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
    - __closebuttoncaption__: set to a string to use as the close button's caption instead of a X. Note that you need to localize this value yourself.
    - __closebuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the
    close button color from default, regardless of being a text or default X. Only has effect if user has location set to `yes`.
    - __footer__: 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.
    - __footercolor__: 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`.
    - __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close.  The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser.
    - __hidenavigationbuttons__: set to `yes` to hide the navigation buttons on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
    - __hideurlbar__: set to `yes` to hide the url bar on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
    - __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`.
    - __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`.
    - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`.
    - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them.  Default value is `yes`.
    - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
    - __shouldPauseOnSuspend__: 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 like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)).
    - __useWideViewPort__: 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`).
    - __fullscreen__: Sets whether the InappBrowser WebView is displayed fullscreen or not. In fullscreen mode, the status bar is hidden. Default value is `yes`.

    iOS supports these additional options:

    - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
    - __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error).
    - __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
    - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened. For WKWebView, requires iOS 11+ on target device.
    - __cleardata__: set to `yes` to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened
    - __closebuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default __Done__ button's color. Only applicable if toolbar is not disabled.
    - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
    - __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the the bounce of the WKWebView's UIScrollView.
    - __hidenavigationbuttons__:  set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled.
    - __navigationbuttoncolor__:  set as a valid hex color string, for example: `#00ff00`, to change from the default color. Only applicable if navigation buttons are visible.
    - __toolbar__:  set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
    - __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
    - __toolbartranslucent__:  set to `yes` or `no` to make the toolbar translucent(semi-transparent)  (defaults to `yes`). Only applicable if toolbar is not disabled.
    - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
    - __enableViewportScale__:  Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
    - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
    - __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`).
    - __presentationstyle__:  Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) (defaults to `fullscreen`).
    - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](https://developer.apple.com/documentation/uikit/uimodaltransitionstyle) (defaults to `coververtical`).
    - __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window.
    - __hidespinner__: Set to `yes` or `no` to change the visibility of the loading indicator (defaults to `no`).

    Windows supports these additional options:

    - __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
    - __hardwareback__: works the same way as on Android platform.
    - __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window.


### Supported Platforms

- Android
- Browser
- iOS
- OSX
- Windows

### Example

    var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
    var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');

### OSX Quirks

At the moment the only supported target in OSX is `_system`.

`_blank` and `_self` targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated.

### iOS Quirks

Since the introduction of iPadOS 13, iPads try to adapt their content mode / user agent for the optimal browsing experience. This may result in iPads having their user agent set to Macintosh, making it hard to detect them as mobile devices using user agent string sniffing. You can change this with the `PreferredContentMode` preference in `config.xml`.

```xml
<preference name="PreferredContentMode" value="mobile" />

上面的示例强制用户代理包含iPad。另一个选项是使用值desktop 将用户代理更改为Macintosh

浏览器怪癖

  • 插件是通过 iframe 实现的,

  • 导航历史记录(位置栏中的后退前进按钮)未实现。

InAppBrowser

当目标设置为'_blank'时,从调用cordova.InAppBrowser.open返回的对象。

方法

  • addEventListener
  • removeEventListener
  • close
  • show
  • hide
  • executeScript
  • insertCSS

InAppBrowser.addEventListener

InAppBrowser中的事件添加侦听器。(仅在目标设置为'_blank'时可用)

ref.addEventListener(eventname, callback);
  • ref: 对InAppBrowser窗口的引用 (InAppBrowser)

  • eventname: 要侦听的事件 (String)

    • loadstart: 当InAppBrowser开始加载 URL 时触发事件。
    • loadstop: 当InAppBrowser完成加载 URL 时触发事件。
    • loaderror: 当InAppBrowser在加载 URL 时遇到错误时触发事件。
    • exit: 当InAppBrowser窗口关闭时触发事件。
    • beforeload: 当InAppBrowser决定是否加载 URL 时触发事件(仅当设置了选项beforeload时)。
    • message: 当InAppBrowser收到从加载到InAppBrowser Webview 中的页面发布的消息时触发事件。
  • callback: 事件触发时执行的函数。该函数将InAppBrowserEvent对象作为参数传递。

示例


var inAppBrowserRef;

function showHelp(url) {

    var target = "_blank";

    var options = "location=yes,hidden=yes,beforeload=yes";

    inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);

    inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);

    inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);

    inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);

    inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);

    inAppBrowserRef.addEventListener('message', messageCallBack);
}

function loadStartCallBack() {

    $('#status-message').text("loading please wait ...");

}

function loadStopCallBack() {

    if (inAppBrowserRef != undefined) {

        inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" });

        inAppBrowserRef.executeScript({ code: "\
            var message = 'this is the message';\
            var messageObj = {my_message: message};\
            var stringifiedMessageObj = JSON.stringify(messageObj);\
            webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);"
        });

        $('#status-message').text("");

        inAppBrowserRef.show();
    }

}

function loadErrorCallBack(params) {

    $('#status-message').text("");

    var scriptErrorMesssage =
       "alert('Sorry we cannot open that page. Message from the server is : "
       + params.message + "');"

    inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);

    inAppBrowserRef.close();

    inAppBrowserRef = undefined;

}

function executeScriptCallBack(params) {

    if (params[0] == null) {

        $('#status-message').text(
           "Sorry we couldn't open that page. Message from the server is : '"
           + params.message + "'");
    }

}

function beforeloadCallBack(params, callback) {

    if (params.url.startsWith("http://www.example.com/")) {

        // Load this URL in the inAppBrowser.
        callback(params.url);
    } else {

        // The callback is not invoked, so the page will not be loaded.
        $('#status-message').text("This browser only opens pages on http://www.example.com/");
    }

}

function messageCallBack(params){
    $('#status-message').text("message received: "+params.data.my_message);
}

InAppBrowserEvent 属性

  • type: 事件名称,可以是loadstartloadstoploaderrormessageexit(String)

  • url: 加载的 URL。 (String)

  • code: 错误代码,仅在loaderror的情况下。 (Number)

  • message: 错误消息,仅在loaderror的情况下。 (String)

  • data: 消息内容,仅在message的情况下。一个字符串化的 JSON 对象。 (String)

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows
  • OSX

浏览器怪癖

loadstartloaderrormessage事件不会触发。

Windows 怪癖

message事件不会触发。

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert(event.url); });

InAppBrowser.removeEventListener

InAppBrowser中删除事件侦听器。(仅在目标设置为'_blank'时可用)

ref.removeEventListener(eventname, callback);
  • ref: 对InAppBrowser窗口的引用。 (InAppBrowser)

  • eventname: 要停止侦听的事件。 (String)

    • loadstart: 当InAppBrowser开始加载 URL 时触发事件。
    • loadstop: 当InAppBrowser完成加载 URL 时触发事件。
    • loaderror: 当InAppBrowser在加载 URL 时遇到错误时触发事件。
    • exit: 当InAppBrowser窗口关闭时触发事件。
    • message: 当InAppBrowser收到从加载到InAppBrowser Webview 中的页面发布的消息时触发事件。
  • callback: 事件触发时执行的函数。该函数将InAppBrowserEvent对象作为参数传递。

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', myCallback);
ref.removeEventListener('loadstart', myCallback);

InAppBrowser.close

关闭InAppBrowser窗口。

ref.close();
  • ref: 对InAppBrowser窗口的引用 (InAppBrowser)

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.close();

InAppBrowser.show

显示一个以隐藏方式打开的 InAppBrowser 窗口。如果 InAppBrowser 已经可见,则调用此方法无效。

ref.show();
  • ref: 对 InAppBrowser 窗口的引用 (InAppBrowser)

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'hidden=yes');
// some time later...
ref.show();

InAppBrowser.hide

隐藏 InAppBrowser 窗口。如果 InAppBrowser 已经隐藏,则调用此方法无效。

ref.hide();
  • ref: 对 InAppBrowser 窗口的引用 (InAppBrowser)

支持的平台

  • Android
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank');
// some time later...
ref.hide();

InAppBrowser.executeScript

将 JavaScript 代码注入InAppBrowser窗口。(仅在目标设置为'_blank'时可用)

ref.executeScript(details, callback);
  • ref: 对InAppBrowser窗口的引用。 (InAppBrowser)

  • injectDetails: 要运行的脚本的详细信息,指定filecode键。 (Object)
    • file: 要注入的脚本的 URL。
    • code: 要注入的脚本的文本。
  • callback: JavaScript 代码注入后执行的函数。
    • 如果注入的脚本类型为code,则回调将使用单个参数执行,该参数是脚本的返回值,包装在Array中。对于多行脚本,这是最后一条语句的返回值,或最后评估的表达式。

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstop', function() {
    ref.executeScript({file: "myscript.js"});
});

浏览器怪癖

  • 仅支持code键。

Windows 怪癖

由于MSDN 文档,调用的脚本只能返回字符串值,否则传递给callback的参数将为[null]

InAppBrowser.insertCSS

将 CSS 注入InAppBrowser窗口。(仅在目标设置为'_blank'时可用)

ref.insertCSS(details, callback);
  • ref: 对InAppBrowser窗口的引用 (InAppBrowser)

  • injectDetails: 要运行的脚本的详细信息,指定filecode键。 (Object)
    • file: 要注入的样式表的 URL。
    • code: 要注入的样式表的文本。
  • callback: CSS 注入后执行的函数。

支持的平台

  • Android
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstop', function() {
    ref.insertCSS({file: "mystyles.css"});
}); __

示例:使用 InAppBrowser 显示帮助页面

您可以使用此插件在应用程序中显示有用的文档页面。用户可以查看在线帮助文档,然后关闭它们,而无需离开应用程序。

以下是一些代码片段,展示了如何执行此操作。

让用户可以请求帮助

在应用程序中有很多方法可以做到这一点。下拉列表是一种简单的方法。


<select id="help-select">
    <option value="default">Need help?</option>
    <option value="article">Show me a helpful article</option>
    <option value="video">Show me a helpful video</option>
    <option value="search">Search for other topics</option>
</select>

在页面的onDeviceReady函数中收集用户的选择,然后将相应的 URL 发送到某个共享库文件中的辅助函数。我们的辅助函数名为showHelp(),我们将在下一步编写该函数。


$('#help-select').on('change', function (e) {

    var url;

    switch (this.value) {

        case "article":
            url = "https://cordova.net.cn/docs/en/latest/"
                        + "reference/cordova-plugin-inappbrowser/index.html";
            break;

        case "video":
            url = "https://youtu.be/F-GlVrTaeH0";
            break;

        case "search":
            url = "https://www.google.com/#q=inAppBrowser+plugin";
            break;
    }

    showHelp(url);

});

加载帮助页面

我们将使用open函数加载帮助页面。我们将hidden属性设置为yes,以便只有在页面内容加载后才显示浏览器。这样,用户在等待内容出现时不会看到空白浏览器。当loadstop事件触发时,我们将知道内容何时加载完成。我们将很快处理该事件。


function showHelp(url) {

    var target = "_blank";

    var options = "location=yes,hidden=yes";

    inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);

    inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);

    inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);

    inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);

}

让用户知道您正在准备他们的页面

由于浏览器不会立即出现,我们可以使用loadstart事件显示状态消息、进度条或其他指示器。这可以确保用户知道内容正在路上。


function loadStartCallBack() {

    $('#status-message').text("loading please wait ...");

}

显示帮助页面

loadstopcallback事件触发时,我们知道内容已经加载完成,我们可以使浏览器可见。这种技巧可以给人一种性能更好的印象。实际上,无论您是在内容加载之前还是之后显示浏览器,加载时间都是完全相同的。


function loadStopCallBack() {

    if (inAppBrowserRef != undefined) {

        inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" });

        $('#status-message').text("");

        inAppBrowserRef.show();
    }

}

您可能已经注意到对insertCSS函数的调用。这在我们的场景中没有任何特殊目的。但这可以让你了解为什么你可能需要使用它。在这种情况下,我们只是确保页面字体的尺寸为特定尺寸。您可以使用此函数插入任何 CSS 样式元素。您甚至可以指向项目中的 CSS 文件。

处理页面错误

有时页面不再存在,脚本错误发生,或者用户没有权限查看资源。如何或是否处理这种情况完全取决于您和您的设计。您可以让浏览器显示该消息,也可以以其他方式显示它。

我们将尝试在消息框中显示该错误。我们可以通过注入一个调用alert函数的脚本来做到这一点。也就是说,这在 Windows 设备上的浏览器中不起作用,因此我们将不得不查看executeScript回调函数的参数,以查看我们的尝试是否成功。如果它对我们不起作用,我们将在页面上的<div>中显示错误消息。


function loadErrorCallBack(params) {

    $('#status-message').text("");

    var scriptErrorMesssage =
       "alert('Sorry we cannot open that page. Message from the server is : "
       + params.message + "');"

    inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);

    inAppBrowserRef.close();

    inAppBrowserRef = undefined;

}

function executeScriptCallBack(params) {

    if (params[0] == null) {

        $('#status-message').text(
           "Sorry we couldn't open that page. Message from the server is : '"
           + params.message + "'");
    }

}

更多使用信息

本地 URL(源在应用程序包中)

var iab = cordova.InAppBrowser;

iab.open('local-url.html');                  // loads in the Cordova WebView
iab.open('local-url.html', '_self');         // loads in the Cordova WebView
iab.open('local-url.html', '_system');       // Security error: system browser, but url will not load (iOS)
iab.open('local-url.html', '_blank');        // loads in the InAppBrowser
iab.open('local-url.html', 'random_string'); // loads in the InAppBrowser
iab.open('local-url.html', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar

白名单内容

var iab = cordova.InAppBrowser;

iab.open('https://whitelisted-url.com');                  // loads in the Cordova WebView
iab.open('https://whitelisted-url.com', '_self');         // loads in the Cordova WebView
iab.open('https://whitelisted-url.com', '_system');       // loads in the system browser
iab.open('https://whitelisted-url.com', '_blank');        // loads in the InAppBrowser
iab.open('https://whitelisted-url.com', 'random_string'); // loads in the InAppBrowser

iab.open('https://whitelisted-url.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar

未列入白名单的 URL

var iab = cordova.InAppBrowser;

iab.open('https://url-that-fails-whitelist.com');                  // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', '_self');         // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', '_system');       // loads in the system browser
iab.open('https://url-that-fails-whitelist.com', '_blank');        // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar