O'Reilly logo

Beginning PhoneGap by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4

Events

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Understanding events
  • Using the events listener
  • Understanding event Types

Now that you’ve learned something about PhoneGap, have installed it, and can make your way around your chosen development environment, it’s time to dive into the PhoneGap API.

In this chapter, you learn how PhoneGap handles events. An event in PhoneGap is similar to other JavaScript events. An action has occurred on the device — for example, the document object model (DOM) has loaded and, therefore, the device is “ready” — and now PhoneGap can do other things in response to it.

Image

NOTE For those of you who have worked in web development, you know that the DOM provides a standardized, versatile view of a document’s contents. By using the DOM, you can easily manipulate a document — adding, removing, and editing nodes as needed. For example, if you want to display status messages to the application user, create an HTML div with an id of statusmessages, then use JavaScript to populate that div with HTML messages.

UNDERSTANDING EVENTS

To put it simply, an event is any action that can be detected by PhoneGap. In traditional JavaScript programming, any element on a web page can have certain events that can trigger a bit of JavaScript. For example, an onrollover event on a link might cause a pop-up window to appear, or an onclick event might cause a preview pane ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required