响应Adsense:无广告位尺寸可用宽度= 0

Kas*_*tin 5 adsense responsive-design twitter-bootstrap

您如何在响应式网站布局上使用Google Adsense响应式块进行操作?让我们考虑一下这种简单的情况(用引导程序编写):

<div class="container">
  <div class="row">
    <div class="col-sm-4 col-md-3">Menu</div>
    <div class="col-sm-8 col-md-6">Content</div>
    <div class="col-md-3 hidden-sm hidden-xs">Column with Adsense</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

因此,对于大屏幕,我们有3列布局,对于小屏幕只有2列。右列不是很重要,因此我们将其隐藏,它包括adsense响应块,我们也将其隐藏。

如果我们在小屏幕上打开此页面,则会收到错误消息TagError: adsbygoogle.push() error: No slot size for availableWidth=0。如何避免这种情况?

理想情况下,如果窗口大小发生变化(在小屏幕上打开然后放大以使第三列变为可见,则应该在出现的列中触发adsense初始化),我想重新初始化adsense块,但是我想现在不可能。

我试图将adsense放到固定大小的容器中(该容器位于hidden-xs块中),它不起作用,无论如何都会出现错误。

我还尝试将响应类添加到中,<ins class="adsbygoogle hidden-xs">...</ins>但它也不能消除错误。

Yov*_*vav 3

我遇到了同样的问题,即使我禁用了 Push() 调用,我仍然收到错误,因为谷歌仍然会在下次调用 Push() 时找到此广告元素(对于不同的广告),

最后,只有当消失的 div 没有隐藏时,我才注入 Fly 的 JavaScript,它才起作用。

<div id="ad-top-right-wrapper" class="hidden-xs col-sm-4 col-lg-3">
    <!-- Portal top right links -->
    /* <ins class="adsbygoogle"
            style="display: block; overflow: hidden;"
            data-ad-test="@googleDataAdTest"
            data-ad-client="ca-pub-9651717958493835"
            data-ad-slot="5910985512"
            data-ad-format="link"></ins> */
    <script>
        // Inject this ad manually when hidden-xs is not in affect (the div is visible)
        // Otherwise google ads will try to push it when the next .push() is called
        if (($("#ad-top-right-wrapper").css("display") !== "none")) {
            document.write("<ins class='adsbygoogle'" +
                " style='display: block; overflow: hidden;'" +
                " data-ad-test='@googleDataAdTest'" +
                " data-ad-client='ca-pub-9651717958493835'" +
                " data-ad-slot='5910985512'" +
                " data-ad-format='link'></ins>");
            (adsbygoogle = window.adsbygoogle || []).push({});
        }
    </script>
</div>
Run Code Online (Sandbox Code Playgroud)