我的应用采用 2 列设计构建,右侧 300 像素列用于显示一个 Adsense 广告单元。
由于有些页面较高,我想知道是否有办法让 jQuery 确定我的 #main_wrapper
的高度,并在超过时显示附加广告单元一定的大小(以像素为单位)。有点像这样:
// ad unit #1 shown here by default in all pages
<script>
$(document).ready(function(){
if ($('#main_wrapper').height() > 660) {
//show add unit #2
}
});
</script>
我的问题是如何处理使用上面的 jQuery/JS 条件包装广告单元代码。典型的广告单元是:
<script type="text/javascript"><!--
google_ad_client = "ca-pub-123123123123";
/* Sidebar 300 Middle */
google_ad_slot = "123123123";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
我如何将其插入到上面的 jQuery 中?
最佳答案
也许您应该将此字符串包含在所需的 block 中?
if ($('#main_wrapper').height() > 660)
{
google_ad_client = "ca-pub-123123123123";
google_ad_slot = "123123123";
google_ad_width = 300;
google_ad_height = 250;
}
关于javascript - 使用 jQuery,如何根据页面高度限制广告单元的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8705967/