Exit the Phonegap-Android Test app on the exit button?

I am new to Phonegap, my application has a login page with username, password, login button and exit button. when I press the exit button, I want to close the application,

<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>

The above was that I tried to close the application when I clicked a button. It works only when I am not registered in the application, if I logged in and try to close the application, click the button to show this error.

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

Please help me solve this problem.

+4
source share
2 answers

Try this code.

        <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>
+4
source

Use the code below to exit the application.

exitApp:function() {   
    app.exitApp();
}
+1
source

Source: https://habr.com/ru/post/1529768/


All Articles