JavaScript implementation checks whether the ads on the page are blocked by Adblock _javascript tips

Source: Internet
Author: User

Everyone hates advertising. Watching TV, watching movies, watching Youku, looking at the Web page, the advertisement is also disgusted with the flying. Advertising is an unattractive thing. However, for a small webmaster/blogger, advertising is almost the only way to support the website/blog normal operation of the source of funds. If a blogger, just the selfless release of manuscripts, can adhere to a few years, very few. Most of them slowly lose their enthusiasm.

Firefox and Google browsers have plug-ins that can screen out ads, most notably Adblock and Adblock Plus. A few days ago, I do a statistic, to see how many users browsing the site to use the Adblock plug-in, found that the number of people who have a total number of visitors 1/5.

1/5 is a large number. How can I get ads to replace them with other images on the 1/5 of users who use the Adblock plugin? To do this, first of all, there is a way to know that the current browser uses the Adblock plug-in. After some tests, I found that adblock to "ad" or "Google ad" is very sensitive to the words, as long as the ID of a page element or CSS class name in the word "ad", this element will basically be blocked by Adblock Plug-ins, that is display: None

Copy Code code as follows:

<div class= ' Google-ad Testad ' > This div will be screened out </div>

With this rule, I was able to use JavaScript to find out whether the current browser has the Adblock plugin open. First, we put the Google ad code in a div and put the div's CSS class name into a clear class name that represents Google ad:

Copy Code code as follows:

<div class= ' Google-ad Testad ' > Place Google Advertising code </div>

Then in the bottom of the page with JS detection,:

Copy Code code as follows:

if ($ ('. Google-ad '). Height () = 0) showotherimage ();

There is also a problem, Google ads usually refers to the DOM after the load is displayed, in order to ensure that Google ads after the completion of the probe, to the JS code to add a delay to perform features, so as to avoid error detection:

Copy Code code as follows:

$ (function () {
settimeout (function () {
if ($ ('. Google-ad '). Height () = 0)
Showotherimage ();
},3000);
});

What can we do in the Showotherimage () method? We can put some of the Jingdong, when, Amazon other websites promotional pictures and links, through the Commission, how much is to compensate for the loss.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.