#*(src*=http://cpro.baidu.com/)

来源:http://thepcspy.com/read/how_to_block_adblock

Blocking Adblock

We start off with our advert code. Most designers nest their code in a positioning element like a <div>. Have a butchers at the following code to see what I’m on about:

<div class="myTestAd" style=" text-align:center;margin:10px"><!-- advert code goes here -->
</div>

In place of the comment there is advert code. This is usually a JavaScript link off to the advertising agency’s website. In the case of Google AdSense, it’s a link off to http://pagead2.googlesyndication.com/pagead/show_ads.js. This script generates the HTML to be displayed on the page inside an iframe. In layman’s‘ terms, an iframe is effectively a web page nested inside a page. This allows Google, in this case, to display their advert to the end user.

So what ends up being rendered is an iframe inside our div. If Adblock is introduced into the equation, the following rule nukes the advert: #*(src*=http://pagead2.)

This is a CSS-selector-based rule that hides any output whose source points to any address beginning with http://pagead2. so the iframe whose source URL does begin with that, is hidden. Not blocked. The JavaScript code still runs but the output is hidden.

Therefore using another chunk of JavaScript at page-level, we can quickly see if the advert has been blocked with this rule. How? We just query the height of the output iframe. If it equals zero, it has been mushed otherwise everything is fine. To do this check we need to call upon the mystic powers of the Document-Object Model but because I’m lazy like that, I’m using the very excellent jQuery library to do all the leg-work. Here is all the JavaScript we need to detect and alert the user they’re blocking adverts:

function TestPage() {if ($('.myTestAd').height() == 0)alert("You are blocking my beautiful adverts, you swine!");
}$(TestPage);

I meant it. A chimp could come up with that. The Window.onDomReady part is a MooTools function that only executes the code when the page is ready to be tested. That is the only nearly-complex thing about it.

Check out the test page

This version just pops up a message box, calls the user a swine and leaves them be but if people wanted to get really obnoxious about their adverts, they could redirect them, blocking them outright.

adblock拦截iframe相关推荐

  1. android html拦截广告,Android WebView拦截iframe标签内部跳转教程

    最近项目里有个广告位需要动态配置,后台给了一段 html 嵌套iframe标签的代码,需要Android拦截iframe内部的跳转,自己做处理. 比如,下面是一段html代码,嵌套这iframe标签, ...

  2. android浮浮窗广告实现,浮窗广告的实现原理

    很多第三方的广告系统都是使用document.write来加载广告,如下面的一个javascript的广告链接: 这个javascript请求返回的是这样的一段代码: 这种加载来自第三方,并且代码都添 ...

  3. ajax请求,请求头是provisional are shown。请求未发送出去

    问题: ajax请求,请求没成功.ajax请求没有发送出去. 查看network,看到请求头处:Provisional headers are shown. 原因: 搜索了一下,网上说了几个原因. 1 ...

  4. 12款程序员专用chrome插件神器推荐

    前言 对于从事IT行业的我们来说,几乎无时无刻都在用chrome浏览器,因为它给我们的工作和生活带来了极大的便利.今天给大家分享11款牛逼的chrome插件. 1. 谷歌翻译 很多小伙伴,英语不太好. ...

  5. chrome 发送请求出现:Provisional headers are shown 提示

    一般来说,如果看到provisional headers are shown这个提示,说明这个请求并没有发送出去. 具体原因有多种总结如下: 1.请求被某些扩展如 Adblock 拦截了,请求被浏览器 ...

  6. safari html5插件安装,Safari巧用小插件 体验不输第三方浏览器

    想必大家平常应该很少使用Safari浏览器,一般都会在手机上下载第三方浏览器来使用,虽然Safari一直在优化但却不及第三方的浏览器来的方便以及用着总有点不顺手.没关系,本篇文章将为您介绍巧妙的装一些 ...

  7. 白帽子讲Web安全读书笔记

    Part1:安全的发展,或者说,黑客的发展 黑客是什么? 互联网本来是安全的,自从有了研究安全的人之后,互联网就变得不安全了. "root"对黑客的吸引,就像大米对老鼠,美女对色狼 ...

  8. 这11款chrome神器,用起来爽到爆

    前言 对于从事IT行业的我们来说,几乎无时无刻都在用chrome浏览器,因为它给我们的工作和生活带来了极大的便利.今天给大家分享我用过的11款牛逼的chrome插件,你看完前3个可能就会忍不住想点赞了 ...

  9. 使用Umami自建网站流量统计

    这篇文章也可以在我的博客查看 Umami 简介 Umami是一个自托管的开源工具,用户可以将其安装在自己的服务器上,并且没有数据采集和共享的问题.Umami的仪表板非常简单易用,而且提供了实时的数据和 ...

最新文章

  1. PHP跳转到另一个画面,并且带着该行内的一个数值作为参数传递给下一个页面.能给例子吗...
  2. java中正则表达式要进行转义的字符。
  3. Qt Creator启动调试器
  4. java thread sleep 效率_Thread.sleep(0):线程休眠0秒有什么意义!
  5. ubuntu 安装 pycharm
  6. 如何给APK文件签名
  7. EasyUI权限(二星权限)
  8. 关于消息推送,你可以知道这个
  9. 应用实例 | 手把手教你用OpenCV实现餐盘水果识别计价程序(附代码)
  10. VCL语法教程——5.手持式1311编程器的支持
  11. windows 快捷键
  12. 2021年四川省大学生信息安全技术大赛部分WP (四川省赛WP)
  13. ACWING133. 蚯蚓(栈)
  14. 改成每天晚上锻炼身体
  15. Docker仓库认证registry
  16. 麻省理工学院计算机系硕士课程,麻省理工学院计算机专业研究生申请 你听说过《算法导论吗》?...
  17. 这个PDF压缩软件值得收藏
  18. Spark Machine Learning(SparkML):机器学习(部分二)
  19. 前端专题 RGB和RGBA( rgb 和 rgba ),及十六进制 颜色介绍
  20. windows系统封装

热门文章

  1. 计算机视觉与深度学习 | 机器学习中的数学——入门机器学习
  2. 论文推荐 | 2018中国卫星导航年会论文集
  3. 位掩码(BitMask)
  4. mac 更换默认蓝牙适配器_蓝牙防丢器实现安卓的BLE接口编程
  5. 视频图像处理平台对比_情绪管理考勤机人脸识别原理与指纹识别性能对比-微幼科技...
  6. 仪表指针样式_Qt自定义Widget之仪表盘
  7. java zookeeper 使用场景_java架构之路-(分布式zookeeper)zookeeper真实使用场景
  8. VC6.0 预编译(转)
  9. python精要(65)-类(2)-构造函数
  10. javascript精要(3)-动态加载脚本