Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Related Plugin Resources
Index

Cordova events


To maximize the benefits of using Cordova, you should know about all the events available. They are called lifecycle events because they are a part of your application throughout its lifecycle. These events are available by default for all applications and it's up to the developer to use them to implement better design. Although there are several events, we will discuss the most important and commonly used events.

The deviceready event

The deviceready event is an important event of Cordova and you can't live without it in the Cordova world. This event is triggered when Cordova has fully loaded and the application is ready to be used. We should know when the application is ready to be used and so this event comes to our rescue. This event should be the gateway to all the application's functionality:

document.addEventListener("deviceready", function() {
    // Application starts here
});

To make the code easy to understand, we can define the function separately and bind it to...