如何在一个页面上使用多个adsense单位?

Mar*_*lln 27 adsense

你如何在一个网站上有多个adsense单位?Google提供的唯一代码是每个单元.

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-123456"
     data-ad-slot="123456"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Run Code Online (Sandbox Code Playgroud)

如果我想在一个网站上使用多个adsense单位怎么办?我只用<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>(adsbygoogle = window.adsbygoogle || []).push({});一次,然后放置<ins ...></ins>在那里我希望它是代码.

问题是只解析和显示了第一个adsense单元.您需要做什么才能显示多个adsense单元?

这是我使用它的方式(仅显示第一个ins):

<!doctype html>
<html>
    <body>
        <ins class="adsbygoogle"
         style="display:inline-block;width:300px;height:250px"
         data-ad-client="ca-pub-123456"
         data-ad-slot="first"></ins>

         <ins class="adsbygoogle"
         style="display:inline-block;width:300px;height:250px"
         data-ad-client="ca-pub-123456"
         data-ad-slot="second"></ins>

         <ins class="adsbygoogle"
         style="display:inline-block;width:300px;height:250px"
         data-ad-client="ca-pub-123456"
         data-ad-slot="third"></ins>

        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Mar*_*lln 74

要在一个页面上拥有多个adsense单元,您必须添加更多行(adsbygoogle = window.adsbygoogle || []).push({});.

因此,如果您有3个广告单元,则需要使用3次.

(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});
Run Code Online (Sandbox Code Playgroud)

如果要动态执行此操作,请使用以下命令:

[].forEach.call(document.querySelectorAll('.adsbygoogle'), function(){
    (adsbygoogle = window.adsbygoogle || []).push({});
});
Run Code Online (Sandbox Code Playgroud)

  • 我每页只能看一个. (2认同)

小智 13

使用jQuery ...

$(".adsbygoogle").each(function () { (adsbygoogle = window.adsbygoogle || []).push({}); });
Run Code Online (Sandbox Code Playgroud)


Has*_*aig 6

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>只需在页面底部(就在 之前)调用一次</body>

接下来,单独放置广告片段,如下所示:

<!-- Top Banner Ad -->
<ins class="adsbygoogle"
    style="display:inline-block;width:320px;height:100px"
    data-ad-client="ca-pub-1234567890"
    data-ad-slot="4693644638"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<!-- Responsive Ad -->
<ins class="adsbygoogle"
    style="display:block"
    data-ad-client="ca-pub-1234567890"
    data-ad-slot="3097818646"
    data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Run Code Online (Sandbox Code Playgroud)