Take the 2-minute tour ×

How can I force an advertisement to show on an ajax-loaded page? Because, as you may know, document.write(); used by AdSense is skipped in asynchronous requests.

I NEED to force that ad to be shown. I also searched on google help forum but with no luck. I found only this but that doesn't tell me anything (it's discontinued).

Note: I also found this topic but I'm not about to refresh these adverts, JUST to show them ! Tried if ($('#advert')){ eval($('#advert')); } before, does not work

Is that possible? Is there some workaround?

share|improve this question
i dont quite understand what you need. is the advert supposed injected into the page after page load? is it built-in the initial page load? –  Dementic Jun 18 '11 at 7:44
after ajax page load, yes. Problm is that browser does ignore document.write() in asynchronous request (look at firebug console and go to any ajax document.write() including page) –  genesis Jun 18 '11 at 7:50
downvoters -> reason ? –  genesis Jun 24 '11 at 21:54
i didnt downvote this question, but i think its because of the "cheat", maybe a google employee visits SO :-/ –  Dementic Jun 25 '11 at 9:47
Damn employeers :D –  genesis Jun 25 '11 at 10:18
add comment

3 Answers

up vote 7 down vote accepted

Sorry, but I think that way of showing AdSense violates Google's TOS. So even if you manage to do that, expect your account to be suspended some time later.


Reference: it is already in the other answers https://www.google.com/adsense/localized-terms

Moreover, some time ago I tried to use ajax loaded page to show adsense and indeed they stopped the account. I also tried Iframe and again the account was suspended. Google don't give a * until you start gaining $$$. So each time it took a while to suspend them. But thrust me they check each site manually at regular basis. So everytime I had to write many letters to google support to restore my accounts and it took a month to restore it and not before I fix the ads. I hate to be dark prophet, but I am pretty sure you will end like me if you mess with google's TOS. My personal advise is to revise your strategy.

I actually may go further and tell you that adsense payment is not very strict, and when something is wrong it is never in your favor. Many colleagues complain about the same, like uncounted clicks, unprovoked account suspensions (usually with significant money to check out), I also have one account that was never able to verify the address, because they don't send me the postcard and I made several requests and waited 2 months each time (for postal delays) and of course I have $$$'s to check out. So mate, don't try to cheat google, because more likely they will cheat you.

This is only my personal view and may contain some strong words that I'm not going to prove, because I'm not trying to start a discussion or accuse anyone.

Edit 2: I also can tell you why google do not allow asynchronous display of ads. Because you can manipulate the context (e.g. put hidden texts) and display non-relevant ads to your page, you can make google show only expensive ads which usually pay $1 per click (well google takes $4+ to the advertiser) and your context may only show $0.05 ads. Other way you could cheat is to simulate clicks or force the user click on ads.

share|improve this answer
It's not an answer –  genesis Jun 24 '11 at 14:19
I disagree. If you ask, "How can I set my hair on fire", then "Don't do that!" is a good response. Though it would be better if it provided references for why one should not want to do that. –  Thom Blake Jun 24 '11 at 15:33
@Thom: Agreed. This is useful information relevant to the question. –  Sinan Ünür Jun 24 '11 at 15:33
What I mean is at that you need to revise your strategy to avoid using what you are thinking you should and I think it is an answer, although it is not what you want to hear. –  venimus Jun 24 '11 at 16:01
No, when I ask "How can I set my hair on fire", you should answer "You can use matches. BuT TAKE THIS SERIOUSLY: Do not do that!" - it's better answer with a tip –  genesis Jun 24 '11 at 16:30
show 3 more comments

Seems like they've stopped google adsense for ajax service now. However, loading ads with javascript is not allowed in google terms of service and may get you banned. https://www.google.com/adsense/localized-terms

You agree to comply with the specifications provided by Google from time to time to enable proper delivery, display, tracking, and reporting of Ads, Links, Search Results, Referral Buttons, and Google Brand Features (as defined in Section 12 below) in connection with Your Property(ies), including without limitation by not modifying the JavaScript or other programming provided to You by Google in any way, unless expressly authorized in writing by Google (including by electronic mail).

share|improve this answer
sorry but. Are you blind? I have given same link in my questi –  genesis Jun 18 '11 at 7:47
I'm sorry I didn't go through each of the links you had in the question. I figured out your problem by reading the content of your question as I had about the same problem and found that it is not allowed by google. –  mridkash Jun 18 '11 at 7:54
it's ok. please edit your answer so I can delete my down-vote –  genesis Jun 18 '11 at 8:00
add comment

Load the page with the ads in a hidden iframe, and just get the contents of that when it's loaded.

I'm not sure it works with Google ad scripts specifically, but it seems to work with javascript in general.

share|improve this answer
I would do it, ONLY PROBLEM is that background is styled with background url and I can't just keep it white –  genesis Jun 22 '11 at 21:12
but +1 for nice idea. Or, could this idea be improved? :) –  genesis Jun 22 '11 at 21:12
You can do display:none on the iframe and still access it with javascript. –  HertzaHaeon Jun 23 '11 at 7:43
so something like <iframe src="ad.php" style="display:none"></iframe><script>$("iframe").WHATNOW?</script> –  genesis Jun 23 '11 at 10:02
Yes, that would hide the iframe. There are several techniques that use iframes this way, many of them listed here on Stack Overflow. jquery/javascript: accessing contents of an iframe. File upload with iframes. –  HertzaHaeon Jun 23 '11 at 18:37
show 1 more comment

Your Answer


