- 添加插件
$ cordova plugin addcordova-plugin-inappbrowser
- 插件的使用
- Methods
cordova.InAppBrowser.open
2. Example
代码语言:javascript复制var ref;
function openBrowser() {
ref = cordova.InAppBrowser.open('https://www.baidu.com', '_blank', 'location=yes');
ref.addEventListener('loadstart', loadStartCallBack);
ref.addEventListener('loadstop', loadStopCallBack);
ref.addEventListener('loaderror', loadErrorCallBack);
}
function loadStartCallBack() {
$('#status-message').text("loading please wait ...");
}
function loadStopCallBack() {
if (inAppBrowserRef != undefined) {
inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
$('#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 removeBrowser() {
ref.removeEventListener('loadstart', loadStartCallBack);
ref.removeEventListener('loadstop', loadStopCallBack);
ref.removeEventListener('loaderror', loadErrorCallBack);
}
function closeBrowser() {
ref.close();
}