I have a a button that once clicked i show an overlay modal div and within this div i embed an adsense code. The code is the following:
$('<div />').addClass('lightbox').appendTo('body').show();
$('<div />').addClass('video_modal').appendTo('body').
css('top', '100px').css('left', $(window).width()/2-200+'px').
html('<div style="width:100%;height:225px;float:left"><script type="text/javascript"><!--\
google_ad_client = "ca-pub-4677950456522449";\
/* Cuadrado_Principal */\
google_ad_slot = "9996968724";\
google_ad_width = 300;\
google_ad_height = 250;\
//-->\
</script>\
<script type="text/javascript"\
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\
</script>\
</div>\
<div class="preloader"></div>\
<div class="preloader_text"Searching...</div>').show();
The question is that preloader and it’s text is shown but not the adsense ad. What’s wrong in my code? I can not understand what’s happening.
Thanks.
My experience says that dynamically adding AdSense is…difficult. Perhaps Google doesn’t allow it and therefor it’s not working. My recommendation is creating a hidden div with the AdSense code and later upon whatever event you’re firing, with jQuery, move the contents of the hidden div to wherever you prefer.
In this example I’ve added an ID to one of your divs called “googleadgoeshere”, and the hidden div is called “adsense”.
It works for me, let me know if you run in to any trouble!