0

広告ブロックを検出したときに何かを表示するように設定しましたが、機能する代わりにコードが表示されています。私はその理由を知るほど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>

ただし、そのコードがある場所では、次のように表示されます。

ここに画像の説明を入力

誰でも助けることができますか?

4

1 に答える 1

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>

wp_register_script () を使用しているときに、wordpress が「text/javascript」ではなく「text/rocketscript」を配置するのはなぜですか? <script>タグを次のように変更する必要があるようです。

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

また、document.write「悪い習慣」と見なされます。おそらく、代わりに DOM 操作を使用する必要があります。つまり、次のようなものです。

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

var content = document.getElementById('content');
content.insertBefore(adblock, content.firstChild);
于 2013-07-07T22:39:24.857 に答える