cordova-plugin-inappbrowser

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

您可以在应用程序内部显示有用的文章、视频和 Web 资源。用户可以在不离开应用程序的情况下查看网页。

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

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

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

window.open

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

window.open = cordova.InAppBrowser.open;

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

InAppBrowser 窗口的行为类似于标准 Web 浏览器,无法访问 Cordova API。因此,如果您需要加载第三方(不受信任的)内容,建议使用 InAppBrowser,而不是将其加载到主 Cordova Webview 中。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.ac.cn', '_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 实现,

  • 未实现导航历史记录(LocationBar 中的 backforward 按钮)。

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.ac.cn', '_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.ac.cn', '_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.ac.cn', '_blank', 'location=yes');
ref.close();

InAppBrowser.show

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

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

支持的平台

  • Android
  • 浏览器
  • iOS
  • Windows

快速示例

var ref = cordova.InAppBrowser.open('https://apache.ac.cn', '_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.ac.cn', '_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.ac.cn', '_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.ac.cn', '_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