【发布时间】:2014-04-20 01:28:15
【问题描述】:
我正在研究我的响应式设计,但在使用 Adsense 时遇到了问题。
我有一个广告应该显示在桌面设计上,而不是移动设计上。 因此,只有在桌面上查看网站时,广告代码才应放在 html 中。 使用 display: none 的 css 是可能的,但这违反了 adsense TOS,所以不是解决方案。
我认为像 http://mobiledetect.net 这样的 PHP 类是可能的,但我更喜欢检查浏览器宽度,然后决定做什么。
Adsense 有一个经过批准的示例,如下所示,但我可以将它用于我的目标吗?
<script type="text/javascript">
google_ad_client = "ca-publisher-id";
width = document.documentElement.clientWidth;
google_ad_slot = "1234567890";
google_ad_width = 320;
google_ad_height = 50;
if (width > 500) {
google_ad_slot = "3456789012";
google_ad_width = 468;
google_ad_height = 60;
}
if (width > 800) {
google_ad_slot = "2345678901";
google_ad_width = 728;
google_ad_height = 90;
}
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
我希望有人能指出我正确的方向。
【问题讨论】:
-
如果您真的想区分台式机和移动设备,检查浏览器宽度不是办法。我的手机分辨率比我的显示器高。您是否更倾向于屏幕尺寸而不是设备类型?
-
它用于响应式设计,因此网站的外观(以及要展示的广告)取决于浏览器的宽度,而不是移动设备与否。我可能解释得有点奇怪:)
标签: javascript jquery mobile responsive-design adsense