Article | Date posted : 11 May, 2014 | Updated on : 11 May, 2014

How to detect if someone is using an Ad Blocker

Sponsored Links

Not everybody likes advertising, and I must admit that I don’t like them ether. There is an acception to the matter and that is if the website you are viewing is trying to earn a small amount of money for the hard work the person or organization has done. Like this website, I try to teach other web developers all my knowledge, which I’m not forcing anything for in return. But if you’re using an Ad Blocker on legitimate websites, than it kind of hurts my feelings.


Explaining what an Ad Blocker does

Ad Blockers applies a CSS styling to the ad element which hides it from your viewing.

How to fix it?

After my research I found that Ad Blocker hides a div element, and a solution was found on stackoverflow.

I have updated the script to reflect the current Google Adsense elements, as at the moment the element using a class named adsbygoogle.

What the script below does is to detect if any element is hidden by Ad Blocker. If it is hidden than send them a message that they are blocking ads.

In my modified example I have inserted a new div element with a message that covers the site.

javascript

$(function(){
setTimeout(function(){
if($(“#ad-top-banner-placeholder, #ad-top-wrapper, #ad-unit, #ad-wrapper, #ad468, #ad728, #ad728x90, #adBanner, #adBelt, #adComponentWrapper, #adDiv, #adFrame, #adGallery, #adHeader, #adHolder, #adLayer, #adLeader, #adPosition0, #adText, #ad_1, #ad_2, #ad_3, #ad_4, #ad_5, #ad_728_90, #ad_area, #ad_banner, #ad_center, #ad_content, #ad_header, #ad_leaderboard, #ad_overlay, #ad_overlay_countdown, #ad_space, #ad_square, #ad_table, #ad_unit, #ad_wrap, #ad_wrapper, #adaptv_ad_player_div, #adbackground, #adbanner, #adbar, #adblock, #adbody, #adbox, #adcode, #adcontainer, #adcontainer1, #adcontent, #adhead, #adheader, #adimg1, #adlayer, #adnews, #adposition3, #adright, #ads-col, #adsHeader, #ads_bottom, #ads_right, #ads_top, #ads_wrapper, #adsdiv, #adsense, #adsense_block, #adsense_inline, #adspace, #adspace_top, #adspot-300×250-pos-1, #adspot-300×250-pos-2, #adtext, #adtop, #adv-masthead, #adv-top, #advert1, #advert2, #advertise, #advertisement1, #advertisetop, #advertising_wrapper, #advtop, #adwrapper, #banner-ad, #bannerAd, #bannerAdWrapper, #banner_topad, #bannerad, #bigAd, #bigad, #body_ad, #bottom_ad, #centerads, #cmn_ad_tag_head, #companionAd, #content-header-ad, #contentAd, #content_ads, #content_adv, #contentad, #dart-container-728×90, #dfp_ad_Entry_728x90, #dfp_ad_Home_728x90, #divAd, #div_prerollAd_1, #download_ad, #featuread, #featured-ads, #featuredAds, #footer_ad, #footer_ads, #game-ad, #google_ads_frame, #google_ads_frame1_anchor, #google_ads_frame2, #googlead, #head-ad, #header-ads, #headerAd, #headerAdContainer, #header_ad, #homead, #ka_adRightSkyscraperWide, #leaderAd, #leaderBoardAd, #leaderboard-ad, #left_ads, #leftad, #leftads, #logoAd, #logo_ad, #mainAd, #main_ad, #mpu2, #mpu2_container, #mpu_container, #msad, #myAd, #player_ads, #pre_advertising_wrapper, #prerollAd, #promo-ad, #publicidad, #reklama, #rh-ad, #right_ads, #right_adsense, #searchAd, #search_ads, #sideAd, #side_ads, #sidebar-ads, #sidebar_ads, #skybox-ad, #sponsorAdDiv, #sponsoredlinks, #sponsors-home, #takeover_ad, #top-ad, #topAd, #topAdSpace, #topAdSpace_div, #topAdvert, #topBannerAd, #top_ad, #top_ads, #topad, #topbannerad, #videoAd, .ADBAR, .AdBody:not(body), .AdBox, .AdInfo, .AdTitle, .AdvertContainer, .HomeAds, .RelatedAds, .SponsoredContent, .ad-300×250, .ad-banner, .ad-block, .ad-border, .ad-btn, .ad-button, .ad-cell, .ad-display, .ad-enabled, .ad-holder, .ad-img, .ad-inner, .ad-item, .ad-leader, .ad-leaderboard, .ad-left, .ad-links, .ad-right, .ad-section, .ad-served, .ad-sidebar, .ad-square, .ad-stack, .ad-text, .ad-top, .ad-unit, .ad-unit-300-wrapper, .ad-vertical-container, .ad-wide, .ad-wrap, .ad-wrapper, .ad160, .ad300, .ad728, .ad90, .adBlock, .adBottomBoard, .adBox, .adContent, .adDiv, .adElement, .adFrame, .adFrameCnt, .adHead, .adHeader, .adHeaderblack, .adHeadline, .adHolder, .adHoldert, .adImg, .adItem, .adLink, .adMiddle, .adMod, .adModule, .adOverlay, .adPanel, .adResult, .adRight, .adRotator, .adSpace, .adSpot, .adText, .adTitle, .adTopHome, .adWidget, .adWrap, .ad_1, .ad_160, .ad_160x600, .ad_2, .ad_3, .ad_728x90, .ad_Right, .ad_body, .ad_container, .ad_description, .ad_global_header, .ad_head_rectangle, .ad_header, .ad_item, .ad_leaderboard, .ad_line, .ad_middle, .ad_outer, .ad_promo, .ad_slug_table, .ad_space, .ad_text, .ad_title, .ad_trick_header, .ad_wrap, .ad_wrapper, .ad_zone, .adarea, .adbanner, .adbar, .adbottom, .adbutton, .adcolumn, .adcont, .addiv, .adframe, .adheader, .adholder, .adinfo, .adlink, .adlist, .admain, .admiddle, .adright, .adrow1, .adrow2, .ads-area, .ads-col, .ads-header, .ads-holder, .ads-inline, .ads-item, .ads-section, .ads-title, .ads-top, .ads1, .adsBlock, .ads_catDiv, .ads_div, .ads_top, .ads_wrapper, .adsbottombox, .adsbox, .adsbygoogle, .adscontainer, .adshome, .adside, .adslot_blurred, .adspace, .adtile, .adtop, .adv_300, .advert-block, .advert-box, .advert-container, .advert-content, .advert-horizontal, .advert2, .advertColumn, .advertContainer, .advertLink, .advertText, .advert_container, .advert_list, .advertbox, .advertisement-1, .advertisement-swimlane, .advertiser, .advertising_block, .advertisment, .advertorial, .adverts, .adverttext, .adwords, .afs_ads, .after-post-ad, .article_ad, .banner-ads, .banner300, .bannerAd, .banner_728x90, .banner_ad, .bannerad, .block-ad, .block-simpleads, .blog-ads, .bottom-ad, .bottom-ads, .bottom-left-ad, .bottomAds, .bottom_ad_block, .box-ads, .boxad, .can_ad_slug, .category-ad, .change_AdContainer, .container_ad, .container_row_ad, .contentAd, .content_ads, .cp-adsInited, .displayAd, .featuredAdBox, .flash-advertisement, .footer-ad, .footer-ads, .footerad, .forumAd, .gallery-ad, .google-sponsored, .googleAdSense, .googleAds, .header-ad, .headerAd, .header_ad, .header_ad_center, .header_advert, .headerad, .headerads, .home-ad, .homeAd, .homead, .homepage-ad, .homepage_ads, .horizontal_ad, .image-advertisement, .imgad, .inner_ad, .innerad, .interstitial_ad_wrapper, .ipsAd, .item-container-ad, .leaderboard-ad, .leaderboard-ads, .leftAd, .leftad, .list-ad, .logo-ad, .marketing-ad, .mid_ad, .middle_AD, .module-ad, .newsAd, .oasad, .openx, .page_ad, .pfAd, .player_ad, .player_hover_ad, .pm-ad, .post-ad, .post_ad, .post_ads, .postad, .premiumAdOverlay, .premiumAdOverlayClose, .promoAd, .publicidad, .rbRectAd, .rectangle_ad, .refreshAds, .region-top-ad-position, .reklam, .reklama, .reportAdLink, .right-ad, .rightAd, .right_ad, .right_ads_column, .rightad, .rightadv, .sb_adsNv2, .searchAds, .searchad, .searchads, .showAd, .side-ad, .side-bar-ad-position1, .single-ad, .singleAd, .sky_ad, .skyscraperAd, .smallAd, .small_ad, .smallads, .sponsor-box, .sponsoredLinks, .sponsorlink, .text-ad, .textad, .textads, .top-ad, .topAds, .top_ad, .top_ad_div, .top_ad_wrap, .top_ads, .topads, .tower-ad, .type_ads_default, .wideAd, .withAds, .wp_bannerize, .yom-ad, a[href^=’http://ad-emea.doubleclick.net/’], a[href^=’http://ad.doubleclick.net/’], a[href^=’http://adultfriendfinder.com/p/register.cgi?pid=’], a[href^=’http://marketgid.com’], a[href^=’http://mgid.com/’], a[href^=’http://pubads.g.doubleclick.net/’], a[href^=’http://us.marketgid.com’], a[href^=’http://www.fbooksluts.com/’], a[href^=’http://www.fleshlight.com/’], a[href^=’http://www.google.com/aclk?’], a[href^=’http://www.liutilities.com/’], a[href^=’http://www.socialsex.com/’], a[href^=’http://www.yourfuckbook.com/?’], a[id^=’mg_add’], div[id^=’MarketGid’], div[id^=’div-gpt-ad-‘], iframe[src^=’http://ad.yieldmanager.com/’]”).css(‘display’)==”none”)
{
$(“.container”).append(“<div class=’adblocked’>We noticed you have an active Ad Blocker. SmileyWar.com is ad funded, we promise our ads are of high quality and are unobtrusive. The best help you could provide to keep us running, is to whitelist us in your ad blocker. Thanks!<br><br><span class=’continuebeingabastard’>Click here to continue anyway and use my hard work for free.</span></div>”);
}
},3000);
});

$(document).on(“click”,”.continuebeingabastard”,function(){
$(“.adblocked”).fadeOut();
});

CSS


.adblocked{
position:fixed;
top:0;
width:100%;
height:100%;
background:#fff;
color:#000;
padding:15px;
z-index:100000;
}

Sponsored Links

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow me on Google+

Google Shopping Data Feed Generator

Sponsored Links

Hire Me