What I did on my vacation from reality

Home About RTL8187B Laptop Cam Quotes Login

November 26, 2007

Tips: Google adsense

10:14 pm — Code, tips

One of the recent improvements to my little blog has been moving Google ads from the sidebar to every third post on the main page. In attempting to detect whether a full-size leaderboard ad would fit, versus a banner ad, I’ve found that loading a responseText object from createXMLHttpRequest doesn’t parse Javascript.

Since there really isn’t any good way to get window resolution from PHP, I hacked around it a bit. See, I have one adsense.php that serves up all the ads. I just do a global $adtheme; ‘checkres’ is a special case that includes some Javascript to detect the window’s internal area.

It basically works like this.

if (window.innerWidth >= 980)
{
  google_ad_width = '728';
  google_ad_height = '90';
  google_ad_format = '728x90_as';
}
else
{
  google_ad_width = '468';
  google_ad_height = '60';
  google_ad_format = '468x60_as';
}

And then the rest of the Google adsense variables.




RSS feed | Trackback URI

Comments»

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.