2011-02-04 57 views
2

我在div中放置了一段廣告代碼,並在頁面底部顯示了一個javascript代碼,用於檢查div的offsetHeight大小。如果返回「0」,我可以安全地假設廣告已被廣告攔截器詆譭刪除廣告內容時顯示圖片

我想要做的是,我想要一個圖像出現在廣告應該顯示的位置當廣告被阻止時。

任何想法如何做到這一點?

編輯:忘記展現代碼

<div id="div_bleh"> 
ads goes here 
</div> 

<script type="text/javascript"> 
function check_blehsize() 
{ 
    if (document.getElementById("div_bleh").offsetHeight == 0) 
     // do stuff 
} 
window.onload = check_blehsize; 
</script> 
+0

問題出在哪裏?你問如何插入一個圖像到這個領域?爲什麼廣告應該被刪除?你有可能嗎?爲什麼你不把你的添加覆蓋在其他div上,其中圖像或文本已經是整個時間,我在一些大頁面上看到了這種方法 – Luke 2011-02-04 17:37:00

+0

剛編輯我的問題,使其更清晰 – Flint 2011-02-04 17:48:50

+0

請顯示一些代碼。 – 2011-02-04 18:01:31

回答

0

下面是我對一個非常常見的廣告攔截測試的例子 - Firefox的Adblock Plus(使用EasyList過濾器):

​​(edit

<!DOCTYPE html> 
<html> 
<head> 
<style type="text/css"> 
.innocent-class { 
    background: url(http://www.google.com/images/logos/ps_logo2.png); 
    width: 240px; 
    height: 400px 
} 


.justForTesting, .advertise_ads { 
    width: 240px; 
    height: 400px; 
    background: #fff 
} 
</style> 
</head> 

<body> 

<div class="innocent-class"> <!-- just don't call it "advertContainer" :) --> 
    <div class="advertise_ads justForTesting"> 
     advert here! 
    </div> 
</div> 

</body> 
</html> 

當Adblock Plus的發現一個使用一個類(例如).advertise_ads,它會隱藏該元素。

如果有,請「請勿阻止我的廣告!」來自父元素的background-image(在這種情況下,Google徽標)將可見。

如果廣告未被阻止,廣告將覆蓋替換圖片。

嘗試將advertise_ads更改爲其他內容,如sdpfjsdfjp,並且廣告將會顯示。

我想這種技術也適用於大多數其他廣告攔截器。

0

假設你知道你會顯示正常情況下你該廣告的大小。

<div class="advert"> 
    <!-- Adverts go here --> 
</div> 

.advert { 
    background-image: url(blah); 
    width: 120px; 
    height: 250px; 
} 

.advert > * { 
    background-color: white; 
} 

當廣告被廣告攔截的時候,這個內容不會顯示。只是一個想法,我從來沒有親自嘗試繞過廣告攔截器。

0

您可以將類添加到該div使用JavaScript(下面的例子中jQuery的), 例如,

adContainer = $(".ad-container"); 
if ($(".ad-container").height() == 0) { 
    adContainer.addClass("no-ads"); 
} 

和CSS將

.no-ads { 
    background: url(the_picture.jpg) no-repeat 0 0; 
    width: ?px; 
    height: ?px; 
}