日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

adblock拦截iframe

發布時間:2025/1/21 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 adblock拦截iframe 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#*(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.

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的adblock拦截iframe的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。