Forum Moderators: martinibuster
The height of the content varies significantly. On some pages, there are only two paragraphs, whereas on others there is significantly more.
I want to use 125x125 AS blocks on the short pages, 120x240 on the med-length pages, and 120x600 on the long ones. This is to avoid large skyscrapers hanging down way past the text, or small ad-blocks with empty space below them.
This works nicely:
<script type="text/javascript"><!--
<!-- Decide on ad size based on content height -->
content_height = document.getElementById("column-content").offsetHeight;
sidebar_height = content_height - 25;
//Default dimentions
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as";
//For long pages
if(sidebar_height > 600){
google_ad_height = 600;
google_ad_format = "120x600_as";
}
//For short pages
if(sidebar_height < 240) {
google_ad_width = 125;
google_ad_height = 125;
google_ad_format = "125x125_as";
}
//Show the adsense block
<!--- Start of standard AdSense code -->
google_ad_client = "pub-blahblahblah";
google_alternate_color = "ffffff";
google_ad_type = "text";
google_ad_channel ="123456789";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000099";
google_color_url = "000099";
google_color_text = "000000";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Technically it's modifying the AdSense code - however the intention obviously isn't malicious. Has anyone got a reply from Google if something similar is allowed?
Of course an alernative would be to re-structure the code so that the original AdSense code is left untouched, but simply wrapped in "if" or "switch" constructs. However this would seem less elegant code-wise, (duplication rather than code reuse).
[edited by: ZoneMR at 11:31 am (utc) on Jan. 28, 2006]
I'm doing something similar (show / hide the DIV with the AS code depending on screen width), and I've never had any complaints from G (knocks on wood).
The answer will almost certainly be no. Maybe you can do something similar in PHP, perhaps using file size to roughly distinguish between shorter and longer pages.
Using PHP to do it is what I'm considering as a last resort. The number of characters in the text is a poor estimate of its rendered height, which will depend on the point at which browsers wrap lines, the resolution and window size, chosen font size, and other client-side factors. The Javascript solution is elegant, and results in neatly laid-out pages with ads that addapt nicely and don't stick out like a sore thumb.
Thanks for your comment on getElementById - although hardly anyone still uses V4 browsers, it won't cost me a lot of time to fix the script to support them.
I realise that the script in it's current form might not be accepted by google, as they probably won't make an exception to their "don't edit our code" policy.
However, hopefully they will accept it in a slightly modified form, which leaves their original code untouched.
if(smallPage) {
original, untouched google code for small adblock
} elseif(medPage)
original, untouched google code for large adblock
}
etc
[edited by: ZoneMR at 7:54 pm (utc) on Jan. 28, 2006]