codecamp

Cordova 返回按钮

处理返回按钮

你通常会想要使用 Android 返回按钮的一些应用程序功能,如返回到上一个屏幕。为了能够实现自己的功能,首先需要在按下返回按钮时禁用退出应用程序。

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown(e) {
   e.preventDefault();
   alert('Back Button is Pressed!');
}

现在,当我们按本机 Android 返回按钮时,警报将显示在屏幕上,而不是退出应用程序。这是通过使用  e.preventDefault() 来完成的。

Event Back Button
Cordova 事件
Cordova Plugman
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }