You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

谷歌广告代码报错Uncaught TagError: No slot size for availableWidth=0求解决

解决谷歌广告No slot size for availableWidth=0错误的可行方案
  • 给广告容器设置明确宽度
    广告加载时容器宽度为0是核心问题,给包裹广告的div添加最小宽度或固定宽度样式,比如:

    <div align="center" style="min-width: 300px; width: 100%;">
    <!-- Sidebar Ads -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="(ad-client-xxxxx)"
         data-ad-slot="(xxxxx)"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    </div>
    

    也可以通过全局CSS给这个容器类设置宽度,避免行内样式冗余。

  • 延迟广告初始化时机
    不要在DOM还没渲染完成时就调用广告push方法,改成页面DOM加载完成后再执行:

    <div align="center">
    <!-- Sidebar Ads -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="(ad-client-xxxxx)"
         data-ad-slot="(xxxxx)"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    </div>
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        (adsbygoogle = window.adsbygoogle || []).push({});
    });
    </script>
    

    如果广告在动态显示的容器里(比如折叠侧边栏),要在容器展开的事件触发后再执行push()。

  • 明确指定广告尺寸
    即使启用了自动适配,也可以给广告添加明确的尺寸参数,帮助谷歌广告确定可用空间:

    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="(ad-client-xxxxx)"
         data-ad-slot="(xxxxx)"
         data-ad-format="auto"
         data-ad-size="300x250"
         data-full-width-responsive="true"></ins>
    

    尺寸值根据你的容器实际大小调整。

  • 排查CSS干扰
    检查页面CSS是否有规则在广告加载时将容器设为display: none、width: 0或visibility: hidden,确保广告容器在加载时处于可见状态且有实际宽度。

内容的提问来源于stack exchange,提问作者aiml_girl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 07:07:31