Reputation: 28437
Is there a way, callback, hack to fire a script/JS function after Google has rendered its ads on your page?
I could simply use a timeOut function, but I'd rather not.
Upvotes: 4
Views: 1417
Reputation: 7108
This is my idea (not tested):
Google creates a set of iframes in which it loads the ad's content. You can find them with a selector (they have an id that is something like: google_ads_frame_BLABLAH). Use the Browser DOM inspector to get the real ID. After finding them, you can add an "onload" listener to know when it's completely loaded.
An example in jquery / pseudocode:
$("iframe").each(function () {
if ($(this).attr("id").match("/google_ads_frame.*/") !== null)
{
$(this).load(function () {
alert("Ad is ready");
});
}
});
You can take count of ads' number that are loaded.
Watch out that if the iframe will internally redirect to another page, the load listener will fire twice.
Upvotes: 2