This is my situation, I have a css 3 column fluid layout (finally mastered the holy grail, thanks everyone!) and in my left column I have a google adsense advert. For those of you familiar with this, they aren't very flexible in the advert sizes, but I am curious if there is a way to change the advert based on the width of the column. Currently this column sits at 20%, so I am thinking maybe a good old fashioned "If - Else" statement might do the trick, but I haven't got it to work yet. The logic is that say we have two ads, a 180 px wide one (a) and a 280 px wide one (b), so if the column is greater than 280 px then it will display advert b, if not then it will display advert a. Has anyone else done this? Thanks!
问问题
469 次
1 回答
0
这里有一些考虑。首先,你用 css 标记了这个问题。如果您只是想使用 css 隐藏您的逻辑已确定不应显示的广告,这样做很简单,但这是一个糟糕的主意。一方面,您将隐藏 Google 明确禁止的已加载广告。接下来,您可能最终隐藏了一个首先加载的广告,因此在您的页面上获得了最“有价值”的点击。您不希望被留下展示价值较低的广告。
您需要做的是在页面加载时使用 javascript来确定视口宽度是多少,然后选择在您正在谈论的广告位中加载哪个广告代码。在尽可能多的浏览器中进行测试,因为您需要确保获得正确的视口宽度才能使该策略起作用。如果由于某种原因它不起作用,请确保后备不会灾难性地折叠布局。这种方法的缺点是如果用户在页面加载后更改视口大小,那么广告将打破边界。您至少可以使用 CSS 来缓解这种极端情况,隐藏或裁剪广告的父 div ( overflow: hidden;
),以便视口大小的更改不会破坏布局。
于 2012-12-25T03:37:21.677 回答