2013-07-07 74 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);