javascript - 使用 jQuery,如何根据页面高度限制广告单元的数量?

标签 javascript jquery

我的应用采用 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/

相关文章:

javascript - 内容未在选项卡中加载

javascript - 当 dom 元素中包含文本删除时,删除整个元素

javascript - 如何提高 IE8 对大数据集的性能?

javascript - 在 javascript 错误上,如何识别有问题的方法或 js 文件?

javascript - 旋转.obj文件OBJMTLLoader Three.js

php - jQuery $.post 请求失败

javascript - Jquery : how to add attributs dynamically with the function . 属性()

javascript - 单滚动(左右)网站

javascript - 如何使用 jQuery 在 5 秒后隐藏文本?

jquery - -moz-transition 在 chrome 中工作但在 firefox safari 中不工作,即请帮助我