13

I am currently working on a Cordova project in Visual Studio. In this project, I am trying building 2 html pages, let me call them first.html and second.html.

In the first.html, I want to add a link to second.html, which allows me to navigate to second.html. I tried 2 ways.

  1. window.location

    window.location = "second.html"
    
  2. tag

    <a href=“second.html”></a>
    

As a result, they both caused an error saying "Exception occurred Message: Exception: Cannot redefine property: org".

Can anyone tell me how to navigate to a new page properly?

Peilin Li
  • 261
  • 1
  • 4
  • 11
  • By the way, I am using ripple to test my app. – Peilin Li Aug 03 '15 at 22:14
  • duplicate? http://stackoverflow.com/questions/12280351/how-navigate-one-page-to-another-page-in-android-phonegap – EugenSunic Aug 03 '15 at 22:17
  • Are the typographical quotes `` ok? – jperelli Aug 03 '15 at 22:18
  • The quotes should be ok. In fact, I have tried the solution mentioned by eugen, but it still gives me the save error. – Peilin Li Aug 04 '15 at 02:31
  • I don't know for sure.but try adding ` ` does it working ? – Shirin Abdolahi Aug 10 '15 at 10:25
  • It shows Cannot GET /%E2%80%9Csecond.html%E2%80%9D – Peilin Li Aug 11 '15 at 23:31
  • You will have a easier time by orders of magnitude if you try to not do all this with just basic javascript+html. Instead, try using Ionic (which uses AngularJS). And use the routing (AngularUI Router) to do your page transitions. Keeps it all SPA so you don't have to track various window instances in cordova and your page transitions will look clean instead of popping into existence instantly. – Bon Aug 12 '15 at 16:47

4 Answers4

14

You can navigate to another page using window.location.href. An example is shown below

    function(){ window.location.href = "second.html";}
Shrinivas Pai
  • 7,491
  • 4
  • 29
  • 56
4

try this it work's for me

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

              <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.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>
</html>
yb3prod
  • 564
  • 2
  • 10
  • 22
2

You can use the below line to navigate one page to another page.

 $('#yourelement').click(function(){      
    window.location.assign('name_of_page.html');
 });
san
  • 214
  • 1
  • 10
2

Try this:

 window.open("second.html"); 

window.open opens a new window/tab with the selected URL, while the mentioned method in the question redirects the current page to the selected URL.

Sourav
  • 17,065
  • 35
  • 101
  • 159
k_kumar
  • 201
  • 1
  • 14