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!
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.
 - 
				
					
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.