vue 使用Adsense错误:TagError: adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them.

复制代码
              <div class="adsenseunit">
                <!-- in-article-aquare2 -->
                <ins
                  class="adsbygoogle"
                  style="display: block"
                  data-ad-client="ca-pub-3935005489954231"
                  data-ad-slot="6650477400"
                  data-ad-format="auto"
                  data-full-width-responsive="true"
                ></ins>
              </div>


            <div class="adsenseunit">
              <!-- in-article-aqure -->
              <ins
                class="adsbygoogle"
                style="display: block"
                data-ad-client="ca-pub-3935005489954231"
                data-ad-slot="4387276146"
                data-ad-format="auto"
                data-full-width-responsive="true"
              ></ins>
            </div>
复制代码
复制代码
 mounted() {
    //启动谷歌unit广告
    let adsenseUnitLength = document.getElementsByClassName('adsbygoogle');
    window.onload = function () {
      for (let i = 0; i < adsenseUnitLength.length; i++) {
        (adsbygoogle = window.adsbygoogle || []).push({});
      }
    };

}
复制代码

在页面中有两个adsense unit,但 document.getElementsByClassName('adsbygoogle') 这个得到的结果是3,可能是因为自动广告开启的缘故,会自动在页面中插入一个带有class=“adsbygoogle” <ins>,导致重复填充。不能用'adsbygoogle这个class name。

posted @   zjhgx  阅读(448)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示