我正在使用google adsense响应式广告。有时adsense找不到ant广告并留下空白。有没有一种方法,使用javascript来确定adsense块是否为空?然后我会隐藏整个adsense容器。
下面是我在adsense中使用的代码:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sidebar skyscrapper -->
<ins class="adsbygoogle"
style="display: block; width: 300px; height: 600px"
data-ad-client="ca-pub-xxxxxx"
data-ad-slot="xxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Sidebar skyscrapper -->
<ins class="adsbygoogle"
style="display: block; width: 300px; height: 600px"
data-ad-client="ca-pub-xxxxxx"
data-ad-slot="xxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>发布于 2021-10-09 01:49:11
谷歌实际上有关于如何处理这个问题的信息-- https://support.google.com/adsense/answer/10762946。ins广告元素中有一个名为data-ad-status的属性,它告诉您广告是“已填充”还是“未填充”。他们建议使用css来隐藏未填充的广告:
<style>
ins.adsbygoogle[data-ad-status="unfilled"] {
display: none !important;
}
</style>如果他们的广告不能为你的页面找到任何东西,你也可以用你自己的图片替换它,链接如下:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"
data-ad-client="ca-pub-1234567890"
data-ad-slot="1234567890">
<a href="/page"><img src="/backup.jpg" width="300px" height="250px"></a>
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<style>
ins.adsbygoogle a {
display: none !important;
}
ins.adsbygoogle[data-ad-status="unfilled"] a {
display: block;
}
</style>https://stackoverflow.com/questions/32416447
复制相似问题