Home > Web Front-end > JS Tutorial > body text

JS code to determine whether web ads are blocked and filtered by the browser_javascript skills

WBOY
Release: 2016-05-16 16:05:51
Original
2410 people have browsed it

It is not as easy to make money by advertising now as it was a few years ago. Most browsers now block ads, and many browsers still block ads by default. Being a webmaster is not an ordinary hardship! At present, most of the income of small and medium-sized webmasters still relies on advertising. If the advertising is blocked, the income will naturally be greatly reduced.

At present, the ad blocking rules of most browsers are to match certain ad words in the ad blacklist, such as Baidu Alliance, Sogou Alliance, and Google Alliance. Even if they are in the ad blacklist, general ad filtering will filter out these ad alliance codes. . The rest is advertising word matching. For example, js addresses containing ads.php, ad.js or even gg.js may be filtered. 360 Browser will even filter images containing ad.gif, 960x90.jpg with advertising words. The addresses will be blocked. If we place customized ads ourselves, we must try to avoid these advertising words.

Faced with ad blocking, asking the browser to add your website to the whitelist is impossible! It's even less practical to tell browsers to disable ad blocking. We can only try to reduce losses as much as possible. Below, Huoduan Network wrote a JS code to determine whether a webpage advertisement has been intercepted and filtered by the browser. After testing with multiple browsers, it can basically be accurately judged. In this way, we can make a judgment and then prompt the user to turn off the ad blocking function, or replace the original advertisement with a custom advertisement, or make it more ruthless and directly make the user inaccessible (this is not recommended).

The judgment code is as follows:

<script src="http://demo.jb51.net/js/2015/adview_pic_cpc_cpm_cpa_guanggao_gg_ads_300x250.js" type="text/javascript"></script> 
<script type="text/javascript">
if (typeof(killads)=='undefined'){alert('广告被过滤');}
</script>
Copy after login

In fact, the content of this js file is a function judgment statement

var killads = true;

The adview_pic_cpc_cpm_cpa_guanggao_gg_ads_300x250.js can be downloaded, but please do not modify the file name.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!