在公用网页或文件出加入
//子页返回触发
<script>
document.addEventListener('plusready', function () {
window.plus.key.addEventListener('backbutton', function () {
var webview = window.plus.webview.currentWebview();
webview.canBack(function (e) {
if (e.canBack) {
webview.back();
}
})
});
});
</script>
//在主页按返回按钮时触发
<script>
document.addEventListener('plusready', function () {
let time = null;
window.plus.key.addEventListener('backbutton', function () {
var webview = window.plus.webview.currentWebview();
webview.canBack(function (e) {
if (!e.canBack) {
if (!time) {
time = new Date().getTime();
window.plus.nativeUI.toast('再按一次退出应用');
setTimeout(function () {
time = null;
}, 1000);
} else {
if (new Date().getTime() - time < 1500) {
window.plus.runtime.quit();
}
}
}
})
});
});
</script>
也可以直接写入js文件引用