3rd party ads (adsense) spacing issues in your website

ads are good but can be annoying at times as they usually bring in some extra html or css that might mess with your layout. take google ads for example, it sometimes inject a fix height and width to an ad even if it doesnt pull in any ads.

so the solution is to implement a custom javascript fix to counter the ads styling:

<script type=”text/javascript”>
jQuery(window).load(function() {
googleFrame = jQuery(‘iframe[id^=”google_ads_iframe_”]’);
googleFrame.each( function () {
if (jQuery(this).contents().find(‘body’).html() == ”) {
jQuery(this).attr(‘height’, ‘0’);
if (jQuery(this).css(‘display’) != ‘none’) {
jQuery(this).closest(‘div’).toggle();
}
}
});
});
</script>

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.