Preventing the default behavior for events

Remember that our applications are run in Safari, which is a web browser and events are handled in a different way than in native applications. In order to implement interfaces for our web applications that are similar to native ones, we'll need to disable the default behavior for these kind of events. This recipe explains how to prevent such behaviors.

How to do it...

  1. First, we need to write one JavaScript function as follows:
    function avoid_behavior(evt) {
  2. The second step will be to write some code for invoking the previous JavaScript function. Actually, this function will be called for different events. Use the following<body> tag for the HTML pages of your application:
    <body ontouchmove="avoid_behavior(event);" ...

Get iPhone JavaScript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.