在退出按钮时退出Phonegap-Android测试应用程序?

问题描述:

我是新来的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 

请帮助我如何解决以下这个问题

使用代码来退出应用程序。

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

试试看看下面的代码。

 <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