diTii.com Digital News Hub

Sign up with your email address to be the first to know about latest news and more.

I agree to have my personal information transfered to MailChimp (more information)


How to advertise on a pure AJAX application?

Kevin Cho, has written a very nice article on “How to advertise on a pure AJAX site?” Here is what Kevin says:

For a while I had a dillema on how to show ad on a 100% ajax web site. It’s totally unfair to show only 1 impression of ads while the user is browsing your site. Currently, I’m using Google’s Adsense and they don’t give any help on Ajax Web thus I had to come w/ my own solution. Of course there was some help on the web to do this but it was a combination of results + my own solution that made it work.

Ok~ so let see what is fair use of this adsense. In my opinion (yours may differ..even Google), if there’s a content change in your web site then it’s fair to show a new ads on your page. Since I’m using AJAX, the best place to refresh the ad would be where you’re making your HTTP request to the server. Example!

var oXmlHttp = createXMLHttp();

oXmlHttp.onreadystatechange = function() {
if (oXmlHttp.readyState == 4) {
var storyDiv = document.getElementById(layerName);
storyDiv.innerHTML = oXmlHttp.responseText;


refreshAd() will refreash the ad. No better place then here. Do not put this under any onClick/onChange/onAnything behavior as it will only complicate your page like onClick=”doSomething();refreshAd();”

// Need to pass unique URI each time to make sure that your browser does not cache the result! This is needed for Firefox specifically!

function refreshAd() {
var currentTime = new Date();
googlead.location = "pages/ad.jsp?s=" + currentTime.getTime();

That’s right! I’m using IFRAME.. I can already see you’re not surprised as if you already know the solution. There’s really no other option since any other solutions will be breaking Google’s TOS.