<!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>
我想問一下,如果用戶想要退出我的應用程序,當它點擊後退按鈕。android phonegap手柄後退按鈕不起作用
,我讀了http://docs.phonegap.com/en/1.2.0/phonegap_events_events.md.html#backbutton 這個例子,但它是不工作...
我該怎麼做才能做到這一點?
我在ONDEVICEREADY功能中設置了一些警報,而且我已經發現這種方法從來沒有使用過......所以EVENTLISTENERE DEVICEREADY從來沒有被燒掉......爲什麼? 非常感謝。
這是你實際使用的代碼嗎?你的'onBackKeyDown()'方法中沒有任何東西。 – Sam
代碼編輯..... – michele
您是否已將onload =「onLoad()」添加到您的身體標記中? – brimil01