Titanium Community Questions & Answer Archive

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

"User Interaction Enable" on a webview (or disable scrolling)

Hi,
is there a way to prevent user interaction on a webview like in Xcode/Interface Builder (Checkbox User Interaction Enabled)?

I want to disable scrolling on my webview.

Thanks!

— asked March 20th 2010 by Niko B
  • scrolling
  • webview
0 Comments

9 Answers

  • Accepted Answer

    You should be able to disable scrolling like this:

    var webView = Ti.UI.createWebView({ ... });
    ...
    webView.addEventListener("touchmove", function(e)
    {
        e.preventDefault();
    });
    
    — answered March 21st 2010 by James K
    permalink
    2 Comments
    • this is wrong.

      — commented July 8th 2011 by Alberto Marcone
    • For the benefit of others looking for the answer, this is not the right approach. As off 1.8.1 using e.preventDefault(); throws exceptions:

      Result of expression 'e.preventDefault' [undefined] is not a function.
      

      To achieve the same result without getting any exceptions add the following to the definition of your WebView…

      touchEnabled: false,
      

      — commented February 14th 2012 by Matthew Delmarter
  • Right answer is, put the following in your HTML:

    <script type="text/javascript">
      document.addEventListener("touchmove", function(e){
        e.preventDefault();
        return false;
      }, false);
    </script>
    
    — answered October 14th 2011 by Jeroen Kntl
    permalink
    0 Comments
  • To disable the scroll on the webview, simply write an empty touchstart function, like this:

    myWebView.addEventListener('touchstart',function(){
    });
    

    It will simply override the default touchstart. :)

    — answered October 19th 2012 by Sufian Babri
    permalink
    0 Comments
  • Thank you. The eventlistener does work (added an alert) but i can still scroll. What am i doing wrong?

    EDIT:
    Got it working:
    I added the e.preventDefault() in touchStart, touchMove & touchEnd directly in the html.
    Thank yout!

    — answered March 21st 2010 by Niko B
    permalink
    2 Comments
    • How did you do that? Please give an example.

      — commented September 6th 2011 by Mattias Lundström
    • For the benefit of others looking for the answer, this is not the right approach. As off 1.8.1 using e.preventDefault(); throws exceptions:

      Result of expression 'e.preventDefault' [undefined] is not a function.
      

      To achieve the same result without getting any exceptions add the following to the definition of your WebView…

      touchEnabled: false,
      

      — commented February 14th 2012 by Matthew Delmarter
  • Hey guys, I had the same problem and e.preventDefault(); worked just fine. Except that my click events aren't working anymore. Looks like e.preventDefault() is preventing every event from being fired or working as default.

    How to prevent the scroll event but still enable the click event?

    — answered October 21st 2011 by Bernardo Oliveira
    permalink
    0 Comments
  • Still looking for the holy grail :)
    I have a webview in a scrollview, the scrollview should scroll, but the web view shouldn't bounce… solutions?

    — answered January 10th 2012 by Gertjan Smits
    permalink
    0 Comments
  • HI,

    I am experiencing the same problem and have search everywhere for an answer without success!

    Has anyone managed to find a solution to this problem and if so please can you post it on this forum.

    Many Thanks!

    — answered January 27th 2012 by Harvinder Sembhi
    permalink
    0 Comments
  • Still waiting, would be nice to get this fixed.

    — answered January 27th 2012 by Gertjan Smits
    permalink
    0 Comments
  • bump

    — answered May 29th 2012 by Matt Pilott
    permalink
    0 Comments
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.