1.0.7 • Published 3 years ago

cordova-plugin-openwebview v1.0.7

Weekly downloads
16
License
MIT
Repository
github
Last release
3 years ago

cordova-plugin-openwebview

This plugin provide capability of open multiple webview, and you can open a new webview in sub webview page.

English | 中文介绍

Screenshot

Supported Platforms

  • Android
  • iOS

Installation

cordova plugin add cordova-plugin-openwebview

Methods

  • cordova.plugins.openWebview.open

cordova.plugins.openWebview.open

cordova.plugins.openWebview.open(openOptions, openSuccess, openError);

Parameters

  • openOptions
  • openSuccess
  • openError

openOptions

OptionsRequiredData TypeDefault ValueDescription
urltrueStringnullTarget url open in webview, not null.
inSubViewfalseBooleanfalseDefault open webview with full screen, if value is true, the effect will like demo.
showBackBtnfalseBooleanfalseDefault hide back button, if value is true, will show it.

Example

var openOptions = {
    url: "https://www.google.com",
    inSubView: false,
    showBackBtn: false
};

function openSuccess(data) {
    console.log(data);
}

function openError(error) {
    console.log(error);
}

cordova.plugins.openWebview.open(openOptions, openSuccess, openError);

Open sub webview

You can use below methods open a new webview in a sub webview page which has been opened with cordova.plugins.openWebview.open, the method only have one option and same as openOptions.

  • window.webkit.messageHandlers.openNew.postMessage (iOS)
  • openWebview.openNew (Android)

window.webkit.messageHandlers.openNew.postMessage

Example

var openOptions = {
    url: "https://www.google.com",
    inSubView: false,
    showBackBtn: false
};

window.webkit.messageHandlers.openNew.postMessage(openOptions);

openWebview.openNew

Example

var openOptions = {
    url: "https://www.google.com",
    inSubView: false,
    showBackBtn: false
};

openWebview.openNew(JSON.stringify(openOptions));

Open url with system browser

If you want to open url with system browser, only need add #webview-external to the end of url.

Example

var openOptions = {
    url: "https://www.google.com#webview-external"
};

cordova.plugins.openWebview.open(openOptions);

// or

window.webkit.messageHandlers.openNew.postMessage(openOptions);

// or

openWebview.openNew(JSON.stringify(openOptions));

TODO

  • Custom action bar background color
  • Custom open webview sum(currently only two webviews can be opened)
  • Post custom message form sub webview

Thanks

License

MIT

Copyright (c) 2020, Vason