【发布时间】:2016-05-11 22:01:43
【问题描述】:
我们使用 Google DFP 在我们的网站上投放来自许多不同广告网络的广告。问题是诈骗者能够以某种方式制作广告,自动将用户重定向到我们的网站。
我想找到一种方法来阻止重定向,因为广告网络似乎没有解决这个问题。他们只是在找到广告时删除广告,然后出现另一个广告。我想出的一种解决方案是将“沙盒”属性添加到 Google 的 iframe。根据我的测试,这似乎有效。
示例:
<iframe id="testframe" src="/test.htm"></iframe>
<script>
$('#testframe')[0].sandbox="allow-scripts";
</script>
/test.htm
<script>
top.location.href = "http://yahoo.com";
alert('javascript still works but no redirect!');
</script>
问题是虽然 DFP 代码是基于 javascript 的,所以我不知道如何将“沙盒”属性附加到动态创建的 iframe。如何在创建 iframe 时但在加载之前添加此属性?或者您有其他解决方案来阻止广告重定向吗?
DFP 代码示例
<div id='dfp-ad-ad_name'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('dfp-ad-ad_name'); });
</script>
</div>
【问题讨论】:
标签: javascript jquery iframe google-dfp