You can make google adsense ads responsive with a simple javascript code. Below I'm giving an amazing trick that will make adsense ads responsive. This simple trick is really cool and will make all adsense ad units responsive automatically. Anyone can use this trick without any experiences.
Google Adsense Responsive Ad Units:
<div id="adsbygoogle">
<script type="text/javascript">
adUnit = document.getElementById("adsbygoogle");
adWidth = adUnit.offsetWidth;
google_ad_client = "ca-pub-number";
if ( adWidth >= 770 ) {
/* Leaderboard 728x90 */
google_ad_slot = "Ad Slot number";
google_ad_width = 770;
google_ad_height = 90;
} else if ( adWidth >= 468 ) {
/* Banner (468 x 60) */
google_ad_slot = "Ad Slot number";
google_ad_width = 468;
google_ad_height = 60;
} else if ( adWidth >= 336 ) {
/* Large Rectangle (336 x 280) */
google_ad_slot = "Ad Slot number";
google_ad_width = 336;
google_ad_height = 280;
} else if ( adWidth >= 300 ) {
/* Medium Rectangle (300 x 250) */
google_ad_slot = "Ad Slot number";
google_ad_width = 300;
google_ad_height = 250;
} else if ( adWidth >= 250 ) {
/* Square (250 x 250) */
google_ad_slot = "Ad Slot number";
google_ad_width = 250;
google_ad_height = 250;
} else {
/* Ad Link Unit (200 x 90) */
google_ad_slot = "Ad Slot number";
google_ad_width = 200;
google_ad_height = 90;
}
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
Customization :
• Replace ca-pub-number with AdSense cab publication number.
• Replace Ad Slot number with AdSense ad slot number
Blogger Comment
Facebook Comment