0

DoubleClick for Publishers (DFP) の広告を使用していますが、1 つの div でjquery append読み込むと、広告ブロックが空になります。DoubleClick for Publishers (DFP) ads広告が正常に表示されるようにするにはどうすればよいですか?

デモリンク

ありがとう。

<?php header("Content-type: text/html; charset=utf-8"); ?>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<?php if(!$_POST['number']){ ?>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=1.7.2'></script>
<script type='text/javascript'>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    (function() {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    var useSSL = 'https:' == document.location.protocol;
    gads.src = (useSSL ? 'https:' : 'http:') + 
    '//www.googletagservices.com/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
    })();
</script>
<script type='text/javascript'>
    googletag.cmd.push(function() {
        googletag.pubads().enableAsyncRendering();
        googletag.defineSlot('/17177879/ads_300_250_white_right', [300, 250], 'div-gpt-ad-1-1').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
    });
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
    $(".bnews").live('click',function(){
        var nnum = $(this).attr('rel');
        googletag.cmd.push(function() {
            googletag.pubads().enableAsyncRendering();
            googletag.defineSlot('/17177879/ads_300_250_white_right', [300, 250], 'div-gpt-ad-' + nnum + '-1').addService(googletag.pubads());
            googletag.pubads().enableSingleRequest();
            googletag.enableServices();
        });
        $(this).css('display','none');
        $.ajax({
            url: "1.php", 
            dataType: "html",
            type: 'POST',
            data: 'number=' + nnum,
            success: function(data){ 
                $("#cc-wrap").append(data); 
            }               
        });
    });
});
</script>
<h1 class="bnews" rel="2">Append to div</h1>
<!-- some content here -->
<!-- ads_300_250_white_right -->
<div id='div-gpt-ad-1-1' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1-1'); });
</script>
<div id="cc-wrap"></div>
<?php }else{ ?>
<h1 class="bnews" rel="<?php echo ($_POST['number']+1); ?>">Append to div</h1>
<!-- some content here -->
<!-- ads_300_250_white_right -->
<div id='div-gpt-ad-<?php echo $_POST["number"]; ?>-1' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-<?php echo $_POST["number"]; ?>-1'); });
</script>
<?php } ?>
4

2 に答える 2

2

googletag.pubads().enableSingleRequest() 関数への 2 つの呼び出しを削除する必要があります...これにより、追加した後にさらに広告をリクエストできなくなっているようです。あなたが使用している2つの場所でそのコードをコメントアウトすると、スクリプトが機能し始めました...それでも少し壊れているようです。

これは、機能するようにコメントされた行の例です。

<?php header("Content-type: text/html; charset=utf-8"); ?>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<?php if(!$_POST['number']){ ?>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js?ver=1.7.2'></script>
<script type='text/javascript'>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    (function() {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    var useSSL = 'https:' == document.location.protocol;
    gads.src = (useSSL ? 'https:' : 'http:') +
    '//www.googletagservices.com/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
    })();
</script>
<script type='text/javascript'>
    googletag.cmd.push(function() {
        googletag.pubads().enableAsyncRendering();
        googletag.defineSlot('/17177879/ads_300_250_white_right', [300, 250], 'div-gpt-ad-1-1').addService(googletag.pubads());
        //googletag.pubads().enableSingleRequest();
        googletag.enableServices();
    });
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
    $(".bnews").live('click',function(){
        var nnum = $(this).attr('rel');
        googletag.cmd.push(function() {
            googletag.pubads().enableAsyncRendering();
            googletag.defineSlot('/17177879/ads_300_250_white_right', [300, 250], 'div-gpt-ad-' + nnum + '-1').addService(googletag.pubads());
            //googletag.pubads().enableSingleRequest();
            googletag.enableServices();
        });
        $(this).css('display','none');
        $.ajax({
            url: "1.php",
            dataType: "html",
            type: 'POST',
            data: 'number=' + nnum,
            success: function(data){
                $("#cc-wrap").append(data);
            }
        });
    });
});
</script>
<h1 class="bnews" rel="2">Append to div</h1>
<!-- some content here -->
<!-- ads_300_250_white_right -->
<div id='div-gpt-ad-1-1' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1-1'); });
</script>
<div id="cc-wrap"></div>
<?php }else{ ?>
<h1 class="bnews" rel="<?php echo ($_POST['number']+1); ?>">Append to div</h1>
<!-- some content here -->
<!-- ads_300_250_white_right -->
<div id='div-gpt-ad-<?php echo $_POST["number"]; ?>-1' style='width:300px; height:250px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-<?php echo $_POST["number"]; ?>-1'); });
</script>
<?php } ?> 

ご不明な点がございましたら、お気軽にお問い合わせください。

于 2012-10-02T17:00:19.853 に答える
0

広告ブロックをiframeに入れるだけで機能します.Google広告コードスクリプトを複製することはできません

于 2012-10-07T10:12:49.717 に答える