Reputation: 7150
deviceready
was no longer fired on second page.
Let's say I have:
page1.html
- entry page.
and
page2.html
- another page.
In page1, I have this code:
document.addEventListener("deviceready", onDeviceReadyPopup, false);
function onDeviceReadyPopup(){
window.location.href="page2.html";
}
In page2, I have this code:
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady() {
alert("Script - Device ready!");
}
Problem: alert was never fired since it does not fire the deviceready
event. This will just work fine in android
.
I doubt that it is because I am using window.location.href
?
Upvotes: 2
Views: 5473
Reputation: 105
deviceready event fires only once per application lifecycle.
This event is essential to any application. It signals that Cordova's device APIs have loaded and are ready to access.
Cordova consists of two code bases: native and JavaScript. While the native code loads, a custom loading image displays.
However, JavaScript only loads once the DOM loads. This means the web app may potentially call a Cordova JavaScript function before the corresponding native code becomes available.
The deviceready event fires once Cordova has fully loaded.
for more: http://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#deviceready
Upvotes: 2
Reputation: 4676
Have you included the device api as all core functionality is now in plugins.
As of 3.x as I undersand it. Adding the following to config.xml worked for me
<gap:plugin name="org.apache.cordova.device" />
I found the information at the bottom of this page Phonegap Build Upgrading from 2.9 to 3.1
Upvotes: 0
Reputation: 627
is it even reaching your ondevicereadypopup() function? maybe try plugging an alert in there to make sure your program reaches it in ios. and also, when i want to change a page in my ios programs i typically handle it this way:
$.mobile.changePage("#idofpage");
the only thing i'm afraid of is that you may be using multiple html files which can make this a little harder, phonegap makes it easy to use all of your pages in one html file and then uniquely ID each page. for example:
<div data-role="page" id="page1">
<!--content of page-->
</div>
when you make your pages like this, then it's extremely easy to navigate to them using their ID's and you can use some good quick transitions between them too.
Upvotes: 1