<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap-1.2.0.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// PhoneGap is loaded and it is now safe to call PhoneGap methods
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {alert("back button pressed");
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
我想问用户是否想退出我的应用程序,当它点击后退按钮时。
我从http://docs.phonegap.com/en/1.2.0/phonegap_events_events.md.html#backbutton阅读了这个例子, 但它不起作用......
我该怎么做呢?
我在 ONDEVICEREADY 功能中设置了一些警报,并且我看到它从未触发此方法....所以 EVENTLISTENERE DEVICEREADY 从未触发...为什么???????非常感谢。