如何在 DFP 生成的 iframe 上添加额外的类名?
How to add an extra classname on iframe, generated by DFP?
我有一个 DFP 广告素材模板,它需要同时适用于新旧网站。
所以在新站点(它有自己的广告组件 js)上,我想在 DFP iframe 上添加一个类名 "redesign"。我该如何正确操作?
总而言之,我希望在 DFP 广告管理系统上使用相同的广告素材模板,并为新网站添加额外的类名。
DFP 使用友好的 iframe。在您的创意模板代码中,您可以找到此 parent iframe 并根据需要应用类名。
在以下示例中,我在名为 "mast_head" 的 div 中呈现我的创意模板。因此 "mast_head" 的第一个 child 将是 DFP 的 iframe。
现在,在我的广告素材模板中,我可以访问此标头元素并应用样式属性,如下所示:
parent.document.getElementById("mast_head").setAttribute("style","height:400px");
这有意义吗?
使用插件解决了 => https://github.com/mcountis/dfp-events
所以在重新设计 ad.js 组件时,我添加了一个新类名 "redesign"。
window.googletag.cmd.push(function() {
window.googletag.on('gpt-slot_rendered', function(e,level,message,service,slot) {
var slotId = slot.getSlotId();
var $slot = $('#' + slotId.getDomId());
// DFP adds two iframes, one for calling scripts and one for displaying the ad. we want the one that is not hidden
if ($slot.find('iframe:not([id*=hidden])')
.map(function() { return this.contentWindow.document; })
.find('body')
.children().length > 0
) {
$slot.find('iframe').contents().find('body').addClass('redesign');
}
});
});
我有一个 DFP 广告素材模板,它需要同时适用于新旧网站。 所以在新站点(它有自己的广告组件 js)上,我想在 DFP iframe 上添加一个类名 "redesign"。我该如何正确操作?
总而言之,我希望在 DFP 广告管理系统上使用相同的广告素材模板,并为新网站添加额外的类名。
DFP 使用友好的 iframe。在您的创意模板代码中,您可以找到此 parent iframe 并根据需要应用类名。
在以下示例中,我在名为 "mast_head" 的 div 中呈现我的创意模板。因此 "mast_head" 的第一个 child 将是 DFP 的 iframe。
现在,在我的广告素材模板中,我可以访问此标头元素并应用样式属性,如下所示:
parent.document.getElementById("mast_head").setAttribute("style","height:400px");
这有意义吗?
使用插件解决了 => https://github.com/mcountis/dfp-events
所以在重新设计 ad.js 组件时,我添加了一个新类名 "redesign"。
window.googletag.cmd.push(function() { window.googletag.on('gpt-slot_rendered', function(e,level,message,service,slot) { var slotId = slot.getSlotId(); var $slot = $('#' + slotId.getDomId()); // DFP adds two iframes, one for calling scripts and one for displaying the ad. we want the one that is not hidden if ($slot.find('iframe:not([id*=hidden])') .map(function() { return this.contentWindow.document; }) .find('body') .children().length > 0 ) { $slot.find('iframe').contents().find('body').addClass('redesign'); } }); });