2

I am trying to change the current HTML page programmatically in PhoneGap (iPhone). Currently I am using window.location.href but it's not doing its job. What is an alternate solution for this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
superGokuN
  • 1,399
  • 13
  • 28

2 Answers2

2

To dynamically change your url when using PhoneGap you really should (perhaps even must) use jQuery mobile; for example -

$.mobile.changePage('index.html', { 
  dataUrl : "index.html?page=events", data : { 
    'page' : 'events' 
  }, reloadPage : false, changeHash : true 
});
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
1

I think you need to use ajax to change html page. If you are using phoneGap api then if you move from one page to other then i will take more time to load phoneGap api. All javascript functions load again so what i prefer that you need to use ajax to load different HTML page.

You need to use JQuery MObile with PhoneGap. JQuery Mobile Load each html page using ajax

Read this for more information

PhoneGap and JQuery Mobile

Dhiral Pandya
  • 10,311
  • 4
  • 47
  • 47
  • There should be a way to do it in simple java script (without using jquery). – Umer Hayat Apr 11 '12 at 06:38
  • Yes you can load entire page using JQuery load() function. In JavaScript See this example http://www.w3schools.com/ajax/default.asp – Dhiral Pandya Apr 11 '12 at 06:40
  • But what if someone doesn't want to use jquery. For example it doesn't make sense to include jquery just to navigate to a different page. Can't it be done using simple JS? – Umer Hayat Apr 11 '12 at 06:44
  • 1
    I got the answer but cause of less reputation i cant answer my question unless 8 hrs. The solution is just have to alter a function in AppDelegate.m file. This is the thread answering my prob: http://stackoverflow.com/questions/5911255/phonegap-for-iphone-problem-loading-external-url – superGokuN Apr 11 '12 at 06:54