2013-07-07 75 views
0

我有一個安裝程序,當它檢測到adblock時顯示的東西,它顯示的代碼,而不是工作。我不是那種有經驗的Javascript知道爲什麼。 好了,在我的索引文件我有Javascript顯示代碼

<script type="text/javascript" src="inls/advertisement.js"></script> 
在advertisement.js

現在我有

document.write('<div id="tester">an advertisement</div>'); 

現在我已經在我的索引之後,繼:

<script type="text/javascript"> 
if (document.getElementById("tester") != undefined) 
{ 
document.write('<center><script type="text/javascript"><!--google_ad_client = "ca-pub-3846434391631935";/* talknow */google_ad_slot = "6591659297";google_ad_width = 728; google_ad_height = 90; //--> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></center>'); 
} else { 
    document.write('<p class="no">We\'ve detected that you\'re using <strong>AdBlock Plus</strong> or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising. Its not nice to steal.<!-- end .content --></p>'); 
} 
</script> 

但代碼如下所示:

enter image description here

任何人都可以幫忙嗎?

+0

我建議你味精一些不同的措詞:「我們檢測到Adblock Plus的或其他一些廣告攔截軟件的能力提供本網站來自如果您不允許顯示這些廣告,則該網站可能無法繼續運作,請允許展示廣告或進行適當的捐贈,以支持本網站。 – jfriend00

+0

@nnnnnn我知道,但就像我說的,我沒有那種Javascript經驗,所以我不知道'是否會破壞代碼,我只是試圖實現一個腳本來滿足我的需求,我沒有編碼這就是我自己 – Austen

+0

你只需要用反斜槓來撇開撇號,你已經這麼做了earlie在同一個字符串中:「我們......你......」。所以只要做同樣的事情:''...它不是......'' – nnnnnn

回答

0

我看了一下你的實際網站的源代碼。這是給你貼什麼不同:

<script type="text/rocketscript"> 
if (document.getElementById("tester") != undefined) 
{ 
document.write('<center><script type="text/javascript"><!--google_ad_client = "ca-pub-3846434391631935";/* talknow */google_ad_slot = "6591659297";google_ad_width = 728; google_ad_height = 90; //--> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></center>'); } else { 
    document.write('<p class="no">We\'ve detected that you\'re using <strong>AdBlock Plus</strong> or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising. Its not nice to steal.<!-- end .content --></p>'); } 
</script> 

基於Why is wordpress placing "text/rocketscript" instead of "text/javascript" when using wp_register_script()?好像你需要你的<script>標籤更改爲:

<script data-cfasync="false" type="text/javascript> 

而且,document.write is considered "bad practice";你應該使用DOM操作來代替,即是這樣的:

var adblock = document.createElement('p'); 
adblock.className = 'no'; 
adblock.innerHTML = 'Some text here'; 

var content = document.getElementById('content'); 
content.insertBefore(adblock, content.firstChild);