Android Phonegap检测backButton事件失败
当我使用Android Phonegap检测backButton事件失败,android,cordova,Android,Cordova,当我使用https://build.phonegap.com/要在android中构建我的应用程序,我处理后退按钮检测的代码不起作用 尽管我使用了以下代码来完成此操作: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=no" /> <meta name="viewport"
https://build.phonegap.com/
要在android中构建我的应用程序,我处理后退按钮检测的代码不起作用
尽管我使用了以下代码来完成此操作:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" href="css/jquery.mobile-1.4.1.min.css">
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery210.js"></script>
<script type="text/javascript" src="js/engine2.js"></script>
<script type="text/javascript" src="js/jqm141.js"></script>
<script type="text/javascript">
function onLoad(){
document.addEventListener('deviceready', function() {
navigator.splashscreen.show();
document.addEventListener("backbutton", ShowExitDialog, false);
}, false);
}
function ShowExitDialog() {
if (navigator.notification) {
navigator.notification.confirm(
("Are you sure ?"),
alertexit,
'Exit',
'Yes,No'
);
}
}
function alertexit(button){
if(button=="1" || button==1){
navigator.app.exitApp();
}
}
</script>
</head>
<body onLoad="onLoad()">
...
</body>
</html>
函数onLoad(){
document.addEventListener('deviceready',function(){
navigator.splashscreen.show();
文档。添加了EventListener(“backbutton”,显示ExitDialog,false);
},假);
}
函数ShowExitDialog(){
if(navigator.notification){
navigator.notification.confirm(
(“你确定吗?”),
警报出口,
"退出",,
“是,不是”
);
}
}
功能警报退出(按钮){
如果(按钮==“1”| |按钮==1){
navigator.app.exitApp();
}
}
...
当按下后退按钮时,我的应用程序没有响应任何内容。如何向后退按钮添加检测功能???使用此简单代码
document.addEventListener("deviceready", appReady, false);
function appReady()
{
document.addEventListener('backbutton', function(e){
if (confirm("Press a button!"))
{
alert("You pressed OK!");
navigator.app.exitApp();
}
else
{
alert("You pressed Cancel!");
}
}, false);
}
你好,Bertho,让我知道你想要android默认后退按钮点击事件还是自定义后退按钮点击事件?Hai@Jeba我想要的是,当用户点击后退按钮时,应用程序将检查页面是否被某个
特定ID访问
应用程序将显示退出警报确认
。因为如果你不喜欢它,那么切换回将做退款页面(历史),这将打开许多页面。我的代码是这样的http://pastebin.com/vZyLF12J