【问题标题】:Attach 'sandbox' attribute to dynamically created iframe to stop redirects将“沙盒”属性附加到动态创建的 iframe 以停止重定向
【发布时间】: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


    【解决方案1】:

    根据GPT documentation,您应该能够通过指定将注入的 iframe 设为沙盒

    setSafeFrameConfig({sandbox: true})
    

    可用于单个槽级别或全局页面级别。

    不确定这是否能有效防止恶意横幅重定向浏览器,但可能值得一试。

    【讨论】:

      猜你喜欢
      • 2019-02-18
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多