2012-11-28 38 views
0
<!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從來沒有被燒掉......爲什麼? 非常感謝。

+0

這是你實際使用的代碼嗎?你的'onBackKeyDown()'方法中沒有任何東西。 – Sam

+0

代碼編輯..... – michele

+0

您是否已將onload =「onLoad()」添加到您的身體標記中? – brimil01

回答

0

看起來你應該看到基於你的代碼和鏈接的警報。然而,該教程適用於1.2版,並且您使用的是2.2版。您可能想要檢查使用相同版本的教程。如果其中一個不存在,則該功能可能已被刪除,或者您需要與Cordova開發人員討論此問題。

+0

我在ONDEVICEREADY功能中設置了一些警報,而且我已經發現這種方法從來沒有使用過......所以EVENTLISTENERE DEVICEREADY永遠不會被燒燬......爲什麼? ???? – michele

+0

如果deviceready未觸發,那麼您的配置或部署可能有問題。 –

+0

我必須看到什麼? – michele

0

如果onDeviceReady()未被觸發意味着PhoneGap尚未加載。 請確保您的cordova-2.2.0.js文件位於正確的位置。根據你的示例「.html」和「cordova-2.2.0.js」文件應該在同一個文件夾中

+0

是的,它是...... – michele