I am looking for a correct implementation method to display/hide my adsense ads on mobile and desktops.
我正在寻找一个正确的实现方法来显示/隐藏我的adsense广告在移动和桌面。
Right now I am using this current method which gives us 2 console errors.
现在我正在使用这个方法,它会给我们两个控制台错误。
The current method is:
当前的方法是:
We use 2 classes "mobileShow" and "mobileno" to tag the ads accordingly to where we want to show them.
我们使用两个类“mobileShow”和“mobileno”来标记广告到我们想要显示的位置。
So if we want the responsive adsense code to be shown on mobiles we use mobileshow if we want to hide the big rectangular ads from mobiles we use mobileno.
所以如果我们想要在手机上显示响应性adsense代码我们就会使用mobileshow如果我们想要在手机上隐藏矩形广告我们就会使用mobileno。
The code we are using is the following:
我们使用的代码如下:
.mobileShow {display: none;}
.mobileShow {display: inline;}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px)
.mobileno{display:none;}
@media (max-width: 767px)
As far as we know google adsense policy allows display:none if it is for a usage like implementing responsive layouts.
据我们所知,谷歌adsense策略允许显示:无,如果是用于实现响应式布局。
Our problem is the we receive the following error 2 times in the chrome development console:
我们的问题是,我们在chrome开发控制台收到以下错误2次:
2 x Uncaught Error: Cannot find a responsive size for a container of width=0px and data-ad-format=auto adsbygoogle.js:41
2 x未捕获错误:无法为宽度=0px和数据-ad-format=auto adsbygoogle.js:41的容器找到响应大小
We have tested several times we know that is something wrong with the above code.
我们已经测试了几次,我们知道上面的代码有问题。
We are looking a way to implement the current "solution" with no errors.
我们正在寻找一种没有错误地实现当前“解决方案”的方法。
We would be very grateful if someone helps us out.
如果有人帮助我们,我们将非常感激。
3 个解决方案
#1
0
I was also unsatisfied with the outcome of completely automatic ad sizes and after a split test I found setting specific sizes for the responsive ads more helpful without losing on performance.
我也不满意完全自动广告大小的结果,在一次分割测试之后,我发现为响应性广告设置特定的大小更有帮助,但不会失去性能。
AdSense gave an example and I just tweaked it with your data.
AdSense给出了一个例子,我只是对你的数据进行了调整。
<style type="text/css">
.adslot_1 { display: none; }
@media (min-width:320px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:480px) { .adslot_1 { display: none; } }
</style>
<ins class="adsbygoogle adslot_1"
style="display:inline-block;"
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>
#2
0
This might be helpful information for future readers:
这对未来的读者可能是有帮助的信息:
Cannot find a responsive size for a container of width=0px and data-ad-format=auto
is an error I get from responsive AdSense ads when I have AdBlock Plus disabled on the current site, but not disabled everywhere.
无法为width=0px的容器找到响应大小,而data-ad-format=auto是我在当前站点禁用AdBlock Plus时从响应性AdSense广告中得到的错误,但不是所有地方都禁用AdSense。
As soon as I check "Disabled everywhere", the AdSense error stops showing up, and responsive AdSense ads show correctly.
一旦我检查“禁用所有地方”,AdSense错误停止显示,响应AdSense广告显示正确。
#3
0
I think your code might be right but a little change could be needed. By changing
我认为您的代码可能是正确的,但是需要做一点修改。通过改变
and (min-device-width : 320px)
和(min-device-width:320像素)
and (max-device-width : 480px)
和(max-device-width:480像素)
to
来
and (min-width : 320px)
and (max-width : 480px)
#1
0
I was also unsatisfied with the outcome of completely automatic ad sizes and after a split test I found setting specific sizes for the responsive ads more helpful without losing on performance.
我也不满意完全自动广告大小的结果,在一次分割测试之后,我发现为响应性广告设置特定的大小更有帮助,但不会失去性能。
AdSense gave an example and I just tweaked it with your data.
AdSense给出了一个例子,我只是对你的数据进行了调整。
<style type="text/css">
.adslot_1 { display: none; }
@media (min-width:320px) { .adslot_1 { width: 320px; height: 50px; } }
@media (min-width:480px) { .adslot_1 { display: none; } }
</style>
<ins class="adsbygoogle adslot_1"
style="display:inline-block;"
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>
#2
0
This might be helpful information for future readers:
这对未来的读者可能是有帮助的信息:
Cannot find a responsive size for a container of width=0px and data-ad-format=auto
is an error I get from responsive AdSense ads when I have AdBlock Plus disabled on the current site, but not disabled everywhere.
无法为width=0px的容器找到响应大小,而data-ad-format=auto是我在当前站点禁用AdBlock Plus时从响应性AdSense广告中得到的错误,但不是所有地方都禁用AdSense。
As soon as I check "Disabled everywhere", the AdSense error stops showing up, and responsive AdSense ads show correctly.
一旦我检查“禁用所有地方”,AdSense错误停止显示,响应AdSense广告显示正确。
#3
0
I think your code might be right but a little change could be needed. By changing
我认为您的代码可能是正确的,但是需要做一点修改。通过改变
and (min-device-width : 320px)
和(min-device-width:320像素)
and (max-device-width : 480px)
和(max-device-width:480像素)
to
来
and (min-width : 320px)
and (max-width : 480px)