我正在使用InApp浏览器并调用页面。我想要的是,如果Internet连接到设备,则必须显示URL,如果未连接,则将显示本地页面。
function onDeviceReady() {
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
var inAppBrowserbRef;
inAppBrowserbRef = window.open('http://www.xxxxx.com', '_self', 'location=no,toolbar=no');
inAppBrowserbRef.addEventListener('loadstart', inAppBrowserbLoadStart)
inAppBrowserbRef.addEventListener('loadstop', inAppBrowserbLoadStop);
inAppBrowserbRef.addEventListener('loaderror', inAppBrowserbLoadError);
inAppBrowserbRef.addEventListener('exit', inAppBrowserbClose);
function inAppBrowserbLoadStart(event) {
var options = { dimBackground: true };
SpinnerPlugin.activityStart("Loading...", options);
if (navigator.connection.type == Connection.NONE)
{ navigator.notification.alert('需要互联网连接
继续',提醒核心,"网络错误","确定");
}
function alertSuccess() {
navigator.app.exitApp();
}
}
function inAppBrowserbLoadStop(event) {
SpinnerPlugin.activityStop();
if (navigator.connection.type == Connection.NONE) {
navigator.notification.alert('An internet connection is required
继续',提醒核心,"网络错误","确定");
}
function alertSuccess() {
navigator.app.exitApp();
}
}
function inAppBrowserbLoadError(event) {
SpinnerPlugin.activityStop();
if (navigator.connection.type == Connection.NONE) {
navigator.notification.alert('An internet connection is required to continue', alertSuccess, "Network Error", "Ok");
}
function alertSuccess() {
navigator.app.exitApp();
}
}
function inAppBrowserbClose(event) {
SpinnerPlugin.activityStop();
inAppBrowserbRef.removeEventListener('loadstart', iabLoadStart);
inAppBrowserbRef.removeEventListener('loadstop', iabLoadStop);
inAppBrowserbRef.removeEventListener('loaderror', iabLoadError);
inAppBrowserbRef.removeEventListener('exit', iabClose);
}
有人知道我要放置重定向页面吗?
您将需要使用Cordova-Plugin-Network-Information插件(看起来您正在使用)来检测在线/离线状态。在您的onDeviceReady()
事件处理程序中,您可以添加听众以响应离线/在线事件:
document.addEventListener("offline", goOffline, false);
document.addEventListener("online", goOnline, false);
function goOffline() {
// Redirect to your local/offline page here
}
function goOnline() {
// Load the actual online content in InAppBrowser
}