I need to insert several AdSense Slots in the same page using javascript.
As you can see in Dynamic Adsense Insertion With JavaScript, it's needed to rewrite the document.write that use the global vars google_ad_client, google_ad_slot, etc..
Like this: (Thanks to https://stackoverflow.com/users/188740/johnnyo)
<script>
window.google_ad_client = "123456789";
window.google_ad_slot = "123456789";
window.google_ad_width = 200;
window.google_ad_height = 200;
// container is where you want the ad to be inserted
var container = document.getElementById('ad_container');
var w = document.write;
document.write = function (content) {
container.innerHTML = content;
document.write = w;
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
document.body.appendChild(script);
</script>
The issue is: If we have just one globla var for slot... How can we insert several ads in the same page using Javascript ?