作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此代码与在我的网站上转换广告有关。顶部是定义每个广告位的地方。然后我有一个可以加载任何单独广告的函数。此函数需要拉取顶部定义的相应广告位变量,但它似乎不起作用。
var slot1;
googletag.cmd.push(function () {
slot1 = googletag.defineSlot('/50970423/ffn-hb-rect-1', [[300, 250]], 'div-1')
.addService(googletag.pubads());
googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
var slot2;
googletag.cmd.push(function () {
slot2 = googletag.defineSlot('/50970423/ffn-hb-rect-ex', [[300, 250]], 'div-2')
.addService(googletag.pubads());
googletag.pubads().disableInitialLoad();
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
function refreshBid(adUnitName) {
if (adUnitName == '/50970423/ffn-hb-rect-1') {
var slot_to_load = slot1;
}
else if (adUnitName == '/50970423/ffn-hb-rect-ex') {
var slot_to_load = slot2;
}
pbjs.que.push(function () {
pbjs.requestBids({
timeout: PREBID_TIMEOUT,
adUnitCodes: [adUnitName],
bidsBackHandler: function () {
pbjs.setTargetingForGPTAsync([adUnitName]);
googletag.pubads().refresh([slot_to_load]);
}
});
});
}
事情是,如果我将末尾附近的那一行更改为 googletag.pubads().refresh([slot1]);它将完美地工作(当然这仅适用于第一个广告位,因为它是硬编码的,所以它不是问题的解决方案)。有任何想法吗?谢谢!
最佳答案
您正在 if/else 语句内部定义 slot_to_load
变量,因此在底线 slot_to_load
是未定义
。在 if/else 外部定义变量,然后在其中设置其值,您的代码将起作用:
function refreshBid(adUnitName) {
var slot_to_load;
if (adUnitName == '/50970423/ffn-hb-rect-1') {
slot_to_load = slot1;
}
else if (adUnitName == '/50970423/ffn-hb-rect-ex') {
slot_to_load = slot2;
}
pbjs.que.push(function () {
pbjs.requestBids({
timeout: PREBID_TIMEOUT,
adUnitCodes: [adUnitName],
bidsBackHandler: function () {
pbjs.setTargetingForGPTAsync([adUnitName]);
googletag.pubads().refresh([slot_to_load]);
}
});
});
}
关于javascript - 无法为预出价槽复制 JS 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584089/
我有一个报告服务报告,但我似乎无法弄清楚如何重新排序表控件中的列。这可以通过直接编辑 rdl 文件来实现吗? 最佳答案 您可以突出显示一列(确保突出显示整列),然后右键单击->CUT。然后突出显示另一
如何获取帐户中关键字的当前出价?我试过了 $adGroupCriterion->biddingStrategyConfiguration->bids[0]->bid->value * AdWordsC
首先,这不是我的专业领域,所以我提前为我在这个领域缺乏直觉和天真而道歉。我只是想帮助一位同事。另外,如果这更适合 DBAdmin StackExchange 站点,请告诉我。尽管有道歉和免责声明...
我是一名优秀的程序员,十分优秀!