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 multiples times on iphone

I have the following code which creates a webview that points to an external url hosting an admob ad and places the webview at the bottom of the current window:

var adUrl = "http://myadurl.com";
var adWebView = null;
var adTimeoutId = null;


function displayAd() {
    var loadingAd = true;
    //create new webview to contain ad.
    if (adWebView) {
    adWebView = new WebView({ url: adUrl, scalesPageToFit: false, height: 48, width: '100%', bottom: 0, left: 0, right: 0 });
    //setup webview event listener for load event.
    adWebView.addEventListener('load', function (evt) {
        if (!loadingAd) {//if not loading ad then it's an ad click.
            var url = evt.url.split('market://').join('http://');
            info("clicked ad " + url);
            //launch ad url in new browser window.
            //load a new ad.
        loadingAd = false;
    //get another ad in 20 seconds.
    if (adTimeoutId) {
    adTimeoutId = setTimeout(displayAd, 20000);

In android it works perfectly, the load event is fired just once as the the ad url is loaded into the webview. Then when you click the ad, it loads the ad destination url which it captures and triggers a launch of that url in the web browser.

However on the iphone simulator I've noticed that when the ad first starts up, it fires off the load event 2-8 times all within a split second. Is this a known bug or am I missing something?

— asked November 19th 2010 by Justin Toth
  • iphone
  • iphone webview
  • you should log the url that are getting loaded and see what it says

    — commented November 20th 2010 by Aaron Saunders
  • I already do that, it's always the url you set in the adUrl variable.

    — commented November 20th 2010 by Justin Toth

0 Answers

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.