Blocking Adsense adblocks
Last update: 07.10.2005
Blocking of ads becomes more and more popular day by day, mostly because of FireFox and it's Adblock extension.
Sure, ads are annoying and offten nasty, but Adsense isn't like that !
If You are a webmaster You can block adsense blockers from viewing your site - it's honest I think...
Everything what You need to do is to place a script published below at the end of You page and put your entire webpage into one DIV.
Below You can see full example code with adsense ad. Only change YOUR-OWN-DIV-NAME, YOUR-INFO-FOR-BLOCKERS and put into your website.
Works with:
- Firefox Adblock
- Firefox RiP (common config)
- Maxthon (MyIE2)
- Simple firewall and hosts file trick (everything that prevents access to adsense host)
- Everything that hides adsense iframe
DOESN'T work with:
- Firefox RiP (sophisticated config)
- Everything that hides content of adsense iframe (inside frame)
<body>
<div id='YOUR-OWN-DIV-NAME' style='visibility: hidden;'>
PAGE-CONTENT
<script type='text/javascript'>
<!--
google_ad_client = 'YOUR-CLIENT-ID';
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = '728x90_as';
google_ad_type = 'text';
//-->
</script>
<script type='text/javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
</script>
PAGE-CONTENT
</div>
<!-- PLACE CODE BELOW JUST BEFORE END OF THE BODY -->
<script type='text/javascript'>
// <![CDATA[
// give browser 1 second to load ads
// setInterval can also be usefull in some cases
setTimeout('show_content()', 1000);
function show_content()
{
var elements, hidden = false;
elements = document.getElementsByTagName('iframe');
for ( var i = 0; i < elements.length; i++ )
{
if ( elements[i].src.indexOf('googlesyndication.com') > -1 )
{
if (! check_visibility( elements[i] ) )
{
hidden = true;
}
}
}
if (! window.google_last_modified_time || ! google_last_modified_time || hidden )
{
alert('YOUR-INFO-FOR-BLOCKERS');
// document.location = 'NO-ADS-URL';
}
else
{
document.getElementById('YOUR-OWN-DIV-NAME').style.visibility = 'visible';
}
}
function check_visibility( obj )
{
if ( obj.setAttribute && ( obj.style.visibility == 'hidden' || obj.style.display == 'none' ))
{
return false;
}
return true;
}
// ]]>
</script>
<!-- THATS ALL MY FRIEND -->
</body>
I'm glad I could help You :)
Please do NOT distribute this code, but link to this site. Thanks :)