Need to manually refresh Admob ads in a PhoneGap (Cordova) project

Go To StackoverFlow.com

1

I'm building a simple content app using PhoneGap + jquery mobile. My AdMob banner is placed at the bottom of each page. The ads appear correctly, but I need them to update/refresh as the user transitions back and forth between pages. Because I'm using jqm's ajax transitions, the pages are cached, and the scripts never reload. I also tried to find an option within the AdMob admin options to set the refresh frequency, but it doesn't appear to exist if I'm using the website embed code.

I tried this:

var admobscript = '<script type="text/javascript" src="http://mmv.admob.com/static/iphone/iadmob.js"><\/script>';
$('#admobbanner').html(admobscript);

But no luck. It feels like an ugly solution anyway and I have a feeling I'm missing something much more elegant. Thanks in advance.

2012-04-05 19:13
by emersonthis


0

If you read through the documentation they offer a few ways to fetch ads:

You could do something like:

_admob.fetchAd(document.getElementById('admobbanner'));

or you could store the ad in an iframe and refresh it like:

<iframe id="admob_ad" style="position: absolute; width: 320px; height: 48px; left: 0px; top: 0px;" noresize="noresize" frameborder="0" src="http://your_site.com/your_admob_web_page.html"></iframe>

<script>
   ...
   // refresh the IFRAME where you want to display a new ad
   var adIframeEl = document.getElementById("admob_ad");

   adIframeEl.src = adIframeEl.src;
   ...
</script>
2012-04-18 23:37
by John Kalberer
I've tried the first option and it doesn't work. If I set manual_mode:true I can add new adds, but they just stack up on top of the original. If I set it to false and leave everything else the same, I get no ads at all.

Just to remove any possible confusion, can you post the actual code snippet as it would appear on a page? I think I'm misinterpreting all the ... throughout their documentation - emersonthis 2012-04-19 10:51

I'm able to refresh the ad manually with the iframe method, but for some reason the 2nd (and all following ads) are shifted left, halfway off the screen - emersonthis 2012-04-19 11:16
That sounds to me like a css or js issue. I can't really do much without some markup, css, and js at this point - John Kalberer 2012-04-19 16:08
I just realized that Google is discontinuing AdMob for mobile in 10 days... so there's not much point in troubleshooting this anymore. Thanks for your help anyway - emersonthis 2012-04-20 16:51
Ads