Titanium Community Questions & Answer Archive

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

WebView 'load' event fires multiple times

When loading certain pages in a webview the load event fires many many times, it even causes Titanium (not the iOS simulator) to crash!

EDIT: Forgot to mention it also fires way too soon, long before it has loaded completely. That's my main problem because I'm trying to fetch the page's HTML when it has finished loading.

It occurs when loading large pages.

This is what i'm doing, very simple:

var url = 'http://www.blt.se';

var webView = Titanium.UI.createWebView({
    width:300,
    height:480,
    top:0,
    url:url
});
win.add(webView);

webView.addEventListener('load', function(){
            alert('Hey!')
});

Anyone else having this problem?

Thanks!

— asked May 13th 2011 by Nils D
  • event
  • eventlistener
  • load
  • multiple
  • webview
5 Comments
  • Found a solution?

    — commented May 30th 2011 by Rasmus Schlünsen
  • I'm having the same issue on 1.7 in Ti Studio

    — commented June 17th 2011 by Brian Blankenship
  • Find a solution? I'm noticing my situation may be partially due to the url having ads on it that point to other urls (I see other NSMutableHTTPRequests being called for the ad pages). Not sure how to prevent this.

    — commented July 11th 2011 by Brian Blankenship
  • I meant "NSMutableURLRequest" for each ad

    — commented July 11th 2011 by Brian Blankenship
  • same issue.. no solutions? :(

    — commented June 13th 2012 by Abhishek Shah

2 Answers

  • Yea, this is due to the fact that the page you are loading, like almost any portal homepage, is comprised almost fully of ajax calls to other pages and scripts, etc. This is going to cause your load event to fire, and fire, and fire again until everything is loaded.

    I suppose one way around this would be listen for the load event and set some interval that if passed would kill the listener and carry on.

    — answered July 11th 2011 by Anthony Decena
    permalink
    3 Comments
    • Thanks, Anthony. I'll do just that. (I would mark this as the best answer for me, but I didn't originate the question.)

      — commented July 12th 2011 by Brian Blankenship
    • Ha, well thanks Brian, I appreciate the sentiment.

      — commented July 12th 2011 by Anthony Decena
    • Is there already a better solution for this available?

      — commented March 22nd 2012 by Wienke Giezeman
  • It might be worthwhile storing the last loaded URL, and checking inside the load event handler if the event's url property is the same as the last.

    — answered May 8th 2013 by remko posthuma
    permalink
    1 Comment
    • What if only the available content needs to be changed, not the whole page? Does the webview need to start the load event again after modifying the content?

      — commented May 14th 2013 by Elvis Mercado
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.