Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...