Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

How to - prevent default touch and mouse events in the BlackBerry WebKit engine

by Retired on ‎07-27-2011 03:43 PM - edited on ‎07-27-2011 03:43 PM by Retired (7,366 Views)

Applies to:


  • BlackBerry® 6
  • BlackBerry® 7
  • BlackBerry® Tablet OS 


Default WebKit engine features and events:


Tthe following WebKit engine features and events are enabled by default.  A web application does not need to manually implement any of these events as they are handled automatically by the BlackBerry WebKit engine: 


  • Mouse events (pressed, move, released, click)
  • Touch scrolling
  • Double tap-to-zoom
  • Pinch-to-zoom
  • Text selection  / context menus 


Using preventDefault:


However, if you wish to disable these WebKit features or replace them with your own functionality, you can do so by overriding the related touch events and calling the preventDefault() method.


Calling preventDefault() from the following touch events will enable/disable the corresponding WebKit engine features:


WebKit engine feature(s) TouchStart TouchMove Only TouchEnd Only
Mouse Pressed Disabled Enabled Enabled
Mouse Move Disabled Disabled* Enabled
Mouse Released Disabled Enabled Disabled
Mouse Click Disabled Enabled Disabled
Touch Scrolling Disabled Disabled* Enabled
Double Tap Zoom Disabled Disabled* Disabled
Pinch Zoom Disabled Disabled* Enabled
Text Selection / Context Menus Disabled Disabled Enabled



* Disabled after the first move is consumed.  E.g. If you have 10 touch move events without calling preventDefault() but then do so on the 11th, these items will be disabled from the 11th event onward.  



For example, if you wish to disable the BlackBerry Web Engine’s pinch-to-zoom feature, call preventDefault() from the ontouchstart event:



document.ontouchstart = function(event) 
   event.preventDefault();   //Disables touch-scrolling AND pinch-to-zoom when called here.
   //Can now do something else with this event.  
   //   E.g. custom scrolling, or a page response for location of this touch event.



More Info:


Users Online
Currently online: 28 members 1,429 guests
Please welcome our newest community members: