我需要使用javascript在同一页面中插入多个AdSense广告位。
正如您在Dynamic Adsense Insertion With JavaScript中所看到的,需要重写使用全局变量google_ad_client,google_ad_slot等的document.write。
喜欢这样:(感谢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>
问题是:如果我们只有一个用于插槽的globla var ...我们如何使用Javascript在同一页面中插入多个广告?