Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In cordova, how to navigate to another html page?

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?

like image 567
Peilin Li Avatar asked Aug 03 '15 22:08

Peilin Li


4 Answers

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.

like image 142
k_kumar Avatar answered Sep 28 '22 22:09

k_kumar


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>
like image 26
yb3prod Avatar answered Sep 28 '22 22:09

yb3prod


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

    function(){ window.location.href = "second.html";}
like image 42
Shrinivas Pai Avatar answered Sep 28 '22 22:09

Shrinivas Pai


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

 $('#yourelement').click(function(){      
    window.location.assign('name_of_page.html');
 });
like image 20
san Avatar answered Sep 28 '22 20:09

san