Ads not showing up sometimes, until I fixed a for loop
-
Very weird problem I was having.
My ads all showed up no problem, except that sometimes on my forum page (which has a bunch of different js includes from my main site), no ads would display. I tracked down the problem: for some reason, in this function (in dfp-ads.js):
function load_ad_positions(positions) { // Run through positions /* for (var ad_pos in positions) { define_ad_slot(positions[ad_pos]); } */ for(var i = 0; i < positions.length; i++) { define_ad_slot(positions[i]); } }
when the original commented-out code was used, sometimes the loop would run an extra time. When I logged the positions object in define_ad_slot(), on the extra loop iteration, all of the object’s values were undefined.
Once I changed it to the uncommented-out loop, it seems to work hunky dory. I have no good explanation, but if there’s any way you could change the loop to work that way, it would be great (so I can use dfp-ads.min.js instead of dfp-ads.js again) ??
- The topic ‘Ads not showing up sometimes, until I fixed a for loop’ is closed to new replies.