Skip to content Skip to sidebar Skip to footer

Javascript Does Not Work On Phonegap Other Than The First Page?

I created a phonegap application, the first page navigates to the second page by 'href'. in the second page, I have a JavaScript function that I want to execute. The problem is tha

Solution 1:

For each page in the application you will have to include the JavaScript code you wish to execute on that page. For instance on page1.html you have a referenced function called getData() you will be able to call it on page1.html. If you follow a href to page2.html the function getData() is now out of scope. It is worth mentioning this is exactly how things work in web browsers.

The way around this is to move getData() to an external JavaScript file like main.js. Then you reference main.js via a script tag in both page1.html and page2.html. Now you'll be able to call getData() from either page.

Solution 2:

Done use anchor tags with href values to change pages. Use the jquery mobile function changePage http://jquerymobile.com/test/docs/api/methods.html to change pages, as changePage wont load a new html fully but would load just the topmost jquert mobile "page" in that html file into the dom.

Post a Comment for "Javascript Does Not Work On Phonegap Other Than The First Page?"