我使用了以下几年,直到我注意到手机和平板电脑上的一个小"bug“,它们才完美地工作:
<script type="text/javascript">
google_ad_client = "ca-pub-XXXX";
if (window.innerWidth >= 888) {
google_ad_slot = "23813373";
google_ad_width = 728;
google_ad_height = 90;
}</script>
<script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>如果你注意到了,我不想显示这个设备宽度小于888px的广告。我在台式机上工作得很好,但在移动和平板电脑上,Adsense显示的是300x150的广告。
是我错过了什么,还是谷歌使用它的代码来优化移动设备上的显示?你注意到同样的问题了吗,虫子?我怎么能不显示这个300x150的广告呢?
发布于 2015-03-17 00:43:14
问题是,无论条件如何计算,代码都会发出广告请求。
解决方案是 one responsive AdSense unit,并将其代码转换为“高级”模式:
<style type="text/css">
.adslot_1 { display: inline-block; width: 728px; height: 90px; }
@media (max-width: 887px) { .adslot_1 { display: none; } }
</style>
<ins class="adsbygoogle adslot_1"
data-ad-client="ca-pub-1234"
data-ad-slot="5678"></ins>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>我认为这段代码已经准备就绪,您只需应用您的publisher ID和您的响应式单元的单元ID,我认为它应该如您所描述的那样工作:“我不想显示设备宽度小于888px的广告”。
(编辑,以澄清:display:none on响应式广告代码中的ins标记将在应用display:none时阻止广告请求,并且它是AdSense中唯一的 of "hiding" an ad unit。发出广告请求,然后隐藏该广告是一个 of the policies。)
https://stackoverflow.com/questions/29076926
复制相似问题