2014-03-03 46 views
4

我是新來的Phonegap,我的應用程序有用戶名,密碼,登錄按鈕和退出按鈕的登錄頁面。當我退出按鈕點擊,我要關閉的應用程序,在退出按鈕時退出Phonegap-Android測試應用程序?

<body> 
<script> 

function exitFromApp() 
      { 
       navigator.app.exitApp(); 
      } 
</script> 
<div data-role="header" data-position="fixed"> 
     <a href="login.html" data-theme="b">Login</a> 
     <h1>Bird on Tree</h1> 
     <button type="button2" onclick="exitFromApp()">Exit</button> 
</div> 

以上是我試圖戒菸的應用程序上按一下按鈕,它僅適用於當我沒有登錄到應用程序,如果我登錄和嘗試退出按鈕的應用程序單擊它顯示了這個錯誤

03-03 01:58:10.457: E/Web Console(1222): Uncaught TypeError: Cannot call method 'exitApp' of undefined at file:///android_asset/www/main.html:5 

請幫助我如何解決以下這個問題

回答

1

使用代碼來退出應用程序。

exitApp:function() { 
    app.exitApp(); 
} 
4

試試看看下面的代碼。

 <script type="text/javascript" charset="utf-8"> 

      function onLoad() 
      { 
       document.addEventListener("deviceready", onDeviceReady, true); 
      } 

      function exitFromApp() 
      { 
       if (navigator.app) { 
        navigator.app.exitApp(); 
       } 
       else if (navigator.device) { 
        navigator.device.exitApp(); 
       } 
      } 

     </script> 

    <body onload="onLoad();"> 
     <button name="buttonClick" onclick="exitFromApp()">Click Me!</button> 
    </body> 
+0

其不工作 – Naresh

+0

你得到了什麼錯誤? – Suhas

+0

立即檢查。我編輯答案。這應該使用phonegap版本2.5.0及更高版本。 – Suhas

相關問題