Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Detecting scroll on a webview

I'm trying to detect scroll (or even just click, any kind of interaction really) on a webview, but can't get it to work. Results are different across platforms. Initially I was trying to open a webview inside a scrollview, but was experiencing some problems getting the webview to actually show. Here, the webview never displays:

var win1 = Titanium.UI.createWindow({  
var wv = Titanium.UI.createWebView({  
    html: '<html><body><h2>Webview in Scrollview Test</h2></body></html>',
var sv = Ti.UI.createScrollView({


So I decided to simplify, taking advantage of the fact that if the content of a webview is longer than the specified height, the view automatically scrolls. However, this code behaves strangely on iPhone and Android:

var win1 = Ti.UI.createWindow({  
var wv = Ti.UI.createWebView({  
    html: '<html><body><h2>Test</h2><p>Testing for touch.</p>
wv.addEventListener('touchend', function(e) {
    Ti.API.info('"heard the touchend event"');

  1. On Android, the event listener never triggers. ('click', 'touchmove', etc don't work either…)
  2. On the iPhone, the event listener triggers, but the webview is no longer scrollable.

Any ideas?

— asked July 26th 2010 by Mark Moyes
  • 1.6
  • api
  • iphone
  • mobile
  • scroll
  • webview

2 Answers

  • Accepted Answer

    True on what Daniel said.
    You can work with the scroll in the webview( so the webpage needs to handle this) and communicate with Titanium using events.

    — answered July 26th 2010 by Dan Tamas
    1 Comment
    • Awesome, thanks. Found your post here:

      …which was enough to get me off and running. It's worth noting that from the DOM, on the iPhone, the Titanium event had to be triggered using the short-form 'Ti.App.fireEvent' and not 'Titanium.App.fireEvent'. This was true for me when compiling on Titanium Developer 1.2.1 using iPhone 3.1 SDK, anyway.

      — commented July 27th 2010 by Mark Moyes
  • On #2, refer to webview API doc, it says

    "Since a webview internally wants to handle its own events, scrolling and other related touch events against it's own view surface, you cannot have both Titanium style events against the webview instance and internal Javascript events in the DOM. You must choose between one or the other."

    So if you any touch, click or similar events on the webview, the webview events itself will not work, such as scrolling. Been there, done that.

    — answered July 26th 2010 by Daniel Lim
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.