Javascript 禁用DFP/双击iFrame

Javascript 禁用DFP/双击iFrame,javascript,google-dfp,Javascript,Google Dfp,在GoogleDFP(双击)中,你会得到一个广告代码放在你的头上,另一个放在你的身体上。当我将这个给定的广告标签/代码应用到我的网站时,无论是异步的还是同步的,广告总是显示在iframe中。我想知道如何禁用iFrame 以下是通过DFP生成的标题代码: <script type='text/javascript'> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; (function() { v

在GoogleDFP(双击)中,你会得到一个广告代码放在你的头上,另一个放在你的身体上。当我将这个给定的广告标签/代码应用到我的网站时,无论是异步的还是同步的,广告总是显示在iframe中。我想知道如何禁用iFrame

以下是通过DFP生成的标题代码:

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/16569348/ad-test-1', [400, 267], 'div-gpt-ad-1362958263281-    0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<!-- ad-test-1 -->
<div id='div-gpt-ad-1362958263281-0' style='width:400px; height:267px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1362958263281-0'); });
</script>
</div>

var googletag=googletag | |{};
googletag.cmd=googletag.cmd | |[];
(功能(){
var gads=document.createElement('script');
gads.async=true;
gads.type='text/javascript';
var usesssl='https:'==document.location.protocol;
gads.src=(使用SSL?'https:':'http:')+
“//www.googletagservices.com/tag/js/gpt.js”;
var node=document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads,节点);
})();
googletag.cmd.push(函数(){
googletag.defineSlot(“/16569348/ad-test-1”,[400267],“div-gpt-ad-1362958263281-0”).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
以下是通过DFP生成的正文代码:

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/16569348/ad-test-1', [400, 267], 'div-gpt-ad-1362958263281-    0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<!-- ad-test-1 -->
<div id='div-gpt-ad-1362958263281-0' style='width:400px; height:267px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1362958263281-0'); });
</script>
</div>

googletag.cmd.push(函数(){googletag.display('div-gpt-ad-1362958263281-0');});
下面是一个JSFIDLE,展示了这个问题(检查google chrome中的元素以查看iframe):

<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/16569348/ad-test-1', [400, 267], 'div-gpt-ad-1362958263281-    0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<!-- ad-test-1 -->
<div id='div-gpt-ad-1362958263281-0' style='width:400px; height:267px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1362958263281-0'); });
</script>
</div>

同样,我想删除iframe(当然保留图像/广告)。。。任何帮助都将不胜感激。:)

来自DFP的网站:

当您使用Google Publisher Tags(GPT)时,您的广告将自动加载到iFrame中


谷歌有意将其广告加载到iFrame中,这是出于设计

之所以这样做,是因为它既可以让页面加载更快,也可以让页面具有沙盒样式和脚本等。页面的呈现速度更快,因为iFrame可以异步加载和呈现广告内容

如果你想的话,你可以用你的广告代码“突围”出iframe,因此在iframe中的广告没有真正的缺点,请给我们一个例子,说明如果你遇到问题,你正在尝试做什么

这里有一些与此相关的问题。

根据我的经验,你的问题(无论是异步的还是同步的)的一部分是错误的。 不确定这是否已更改,或者是否未能让GPT标记同步运行,但由于我更改为同步模式,iFrame不再使用。
请参见

我们也遇到了同样的问题,因为我们的目标是将本地广告直接添加到主机页面DOM,而不是使用IFRAME来获得完全响应。我们提出了一个解决方案,我们使用消息将广告内容字符串发布到主机页。这样就没有了IFRAME

详情请参阅


请注意,我们仅使用此方法运行房屋广告,而不是任何可能导致意外行为的第三方广告

我为一个数字广告商工作,你永远不应该禁用来自广告的iFrame

ADS可以包含完整的脚本,所以最好使用安全框架(框架使用src指向外国来源点)来防止这种情况


还有许多广告脚本使用
文档。写
,在他们的iframe中,他们可以毫无问题地做到这一点,他们会在
文档之后的主窗口中这样做。准备好了
会把你的页面涂成空白。

nooooooo!!!!:(这很糟糕,但同时…谢谢你的回答。你知道有没有其他方法可以在不进入iframe的情况下制作广告?这将非常有用。如果你使用Google广告管理器标签,看起来你可以绕过iframe。你知道这是否会产生尺寸(高度和宽度)我能把广告的宽度改成一个百分比而不是像素吗?从我发给你的页面中的文档判断,是的:GA_googleAddSlot(“ca-pub1”,“GizmosUnlimited_HelpCenter_FAQ_ATF_Left_90x90”);GA_GoogleAddSensePageAttr(“google_color_bg”,“F0F0”)感谢你的帮助,我遇到了一个问题,因为我试图将图像广告宽度更改为一个百分比,而不是像素…这里的问题解释了一切:如果你愿意,请随时提供帮助:)你知道如何“抓拍”吗在iframe之外?我希望您可以发送额外的参数,告诉它使用百分比宽度,或者在iframe内的广告中添加内联样式。。。如果他们要在运行中生成它们,为什么不给我们更多的微调控制呢?!这就像谷歌从未听说过响应式设计。。。而且,不,我不想为每种尺寸设置单独的广告。这对于管理几十个广告的人来说是很好的,但是我管理了几百个。对我们来说,很多时候,它显示一个iframe而没有真正加载广告,不确定解决方案是什么??