- 子页面
//这个不是写在首页,写在子页面(子页面才能返回,写在首页点击返回就是退出)
//不用引入mui.js,都是h5方法
document.addEventListener('plusready', function() {
var webview = plus.webview.currentWebview();
plus.key.addEventListener('backbutton', function() {
webview.canBack(function(e) {
if(e.canBack) {
webview.back();
} else {
webview.close(); //hide,quit
//plus.runtime.quit();
}
})
});
});
2. 首页点击两次退出程序
//这个写在首页,判断连击两次退出。
//需要引入mui.js版本,我当时测试的时候引入了,如果不想引入把带mui的都删了就可以(或者看下面那个)
mui.plusReady(function() {
//首页返回键处理
//处理逻辑:1秒内,连续两次按返回键,则退出应用;
var first = null;
plus.key.addEventListener('backbutton', function() {
//首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}, false);
});
//不需要mui.js版本
document.addEventListener('plusready', function(a) {
var first = null;
plus.key.addEventListener('backbutton', function() {
//首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
console.log('再按一次退出应用');//用自定义toast提示最好
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}, false);
});
Comments | NOTHING