Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate one page to another page in android phonegap?

I am new to PhoneGap.

My application has to 2 pages. The first is loading fine. First page contains one buttons, which when clicked should move to the second page. How to load the second page? Should I prepare one more activity extending DriodGap?

I have one more problem: how to catch back button events?

like image 399
SuReSh PaTi Avatar asked Sep 05 '12 11:09

SuReSh PaTi


2 Answers

Code to navigate to another html page.

<!DOCTYPE HTML>
<html>
  <head>
    <title>PhoneGap</title>

          <script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>      
          <script type="text/javascript" charset="utf-8">

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

             function onDeviceReady()
             {
                  // navigator.notification.alert("PhoneGap is working");
             }

             function callAnothePage()
             {
                window.location = "test.html";
             }

          </script>

  </head>

  <body onload="onLoad();">
        <h1>Welcome to PhoneGap</h1>
        <h2>Edit assets/www/index.html</h2>
        <button name="buttonClick" onclick="callAnothePage()">Click Me!</button>
  </body>

Code for back Event.

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

             document.addEventListener("deviceready", onDeviceReady, true);

             function onDeviceReady()
             {     
                   document.addEventListener("backbutton", BackKeyDown, true);
             }

             function BackKeyDown()
             {
                 navigator.notification.alert();
                 //navigator.app.exitApp();  // For Exit Application
             }
        </script>
like image 96
Chirag Avatar answered Nov 02 '22 02:11

Chirag


You need to redirect from Javascript like this:

HTML Code:

<a id="loginLnk" href="javascript:(void)">Login</a>

Javascript code:

document.getElementById("loginLnk").addEventListener("click", function(){window.location = "/test.html";});
like image 22
NK_Mimrot Avatar answered Nov 02 '22 00:11

NK_Mimrot