Hodaya Shalom
Hodaya Shalom

Reputation: 4417

href not working, how to redirect to a specific page in PhoneGap?

In Html5 I go to a specific page in the following manner:

window.location.href = "http://localhost:XXXX/MyPageName.html";

The href by clicking on the button does not work!! I have no idea why, it's the only way I could solve this problem.

When I run the html5 application using the PhoneGap, the links do not work (obviously, since there is no localhost to application)

How can I solve this problem?

Upvotes: 4

Views: 7154

Answers (3)

A. Magalhães
A. Magalhães

Reputation: 1516

You will solve your problems using something like this:

<script>
    //action go to pageOther
    $.mobile.changePage('#pageOther','slide');
</script>
<body>
    <div data-role="page" id="pageHome">
        //Your html
    </div>
    <div data-role="page" id="pageOther">
        //Your html
    </div>
</body>

See more info: http://jquerymobile.com/demos/1.2.0/docs/pages/page-anatomy.html

Upvotes: 1

malteseKnight
malteseKnight

Reputation: 347

Phonegap suggest not having multiple pages. You should have "content" section in one page and then through the dynamic linking (using #page1 where page1 is the content area id)

Example.

all in same html page (index.html)

<div data-role="page" id="page0">
<a data-role="button" data-transition="slide" href="#page1">Page 1</a>
<div>

<div data-role="page" id="page1">

<div>

Upvotes: 1

davidpfahler
davidpfahler

Reputation: 606

First, your links might not work, because cordova/phonegap blocks all external URLs by default. To fix this, read my answer here.

Second, Phonegap does not open a webserver, so http://localhost is not correct. When you want to have an internal link, use something like <a href="/mydir/mypage.html">linkText</a>.

Upvotes: 2

Related Questions