根据边栏高度动态生成Google广告

问题描述 投票:0回答:1

我有一个网页,我在侧边栏上显示Google广告。

站点:https://www.pragimtech.com/blog

根据adsense Terms & Conditions,我们不应在侧边栏上保留粘性广告。

我在侧边栏中有一个广告,其行为是“ scrollable”。

这里的问题是,当用户向上滚动页面时,广告将向上滚动,而页面侧边栏中的剩余空间将被浪费。

即使用户向上滚动页面,有没有更好的解决方案来利用侧栏中的空格。 (即,在边栏中动态生成广告)

提前感谢...

javascript html css ads adsense
1个回答
0
投票

我将使用JavaScript的滚动高度功能来获取用户在加载页面时的页面高度,然后相应地放置许多广告。像这样的东西:

var docHeight = document.body.scrollHeight
var sidebarNo = Math.floor(document.body.scrollHeight/("Size of your ad here" + "More for padding"))
//We use Floor as it doesn't make sense to have half an ad. And we don't want to go over.
//sidebarNo is the number of ads we can put on the side bar without adding more space.
//Then use a for loop to place sidebarNo of ads with JavaScript

我将其设置为在页面加载时运行。如果只是在您的网页上运行,则用户在调整窗口大小时可能会显示更多广告,这可能会很烦人。

可能有一个更优雅的解决方案,但这就是我的想法。

© www.soinside.com 2019 - 2024. All rights reserved.