无需在网站上放置任何代码的插页式广告(异步广告)
Interstitial ads (asynchronous ads) without placing any code on the website
我正在尝试创建一个投放灯箱的广告,但广告本身将被放置在注入网站的 iframe and/or 中(不同的域).有些站点会将它放在 iframe 中,而有些则按原样放在站点上。我将无法控制要放置广告的网站。
我知道我可以使用 postMessage()
从 iframe 中发送数据并使用接收到的数据在父级 window 上执行命令,但我不能在父级上放置任何代码window。是否有适用于两种场景的通用解决方案?我想推送一些内容给父级 window.
这段代码完全符合我的要求,但我不知道它是如何做到的:
<script src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=17085731&PluID=0&w=1&h=1&ord=[timestamp]&ucm=true&ncu=$$%c$$"></script>
<noscript>
<a href="%chttp%3A//bs.serving-sys.com/BurstingPipe/adServer.bs%3Fcn%3Dbrd%26FlightID%3D17085731%26Page%3D%26PluID%3D0%26Pos%3D67849382" target="_blank"><img src="%%VIEW_URL_ESC%%.http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=17085731&Page=&PluID=0&Pos=67849382" border=0 width=1 height=1></a>
</noscript>
如果代码在 frame/iframe 中并且您无权访问 parent frame/window 并且 parent frame/window 没有 API 通过 postMessage()
设置加载 pop-over/lightbox 那么答案是否定的。
您唯一可以执行此操作的情况是使用友好的 iFrame(与 parent frame/window 相同的域)或采取解决方法以允许访问 parent frame/window。请注意,即使这样做了并且您访问并更改了 parent 如果他们不期望您尝试添加的内容或者您有意或无意地更改,您可能会激怒框架所在网站的发布者或所有者他们的网站或样式表以任何方式或注入可能是恶意的脚本。如果你反复这样做,你也可能会被你发送广告的任何网络禁止。
如果使用 SafeFrame,您将无法做到这一点。 SafeFrame 旨在防止广告商更改顶层 window/frame 它提供了一个 API 来展开广告,如果它是一种可扩展的广告类型,但 SafeFrame API 中没有弹出窗口。
如果您想测试是否可以访问 parent/top frame/window,您可以尝试:
前frame/window:
try { window.top.location.href } catch(e) {
// Exception was thrown meaning you do not have access to the top window/frame!
}
对于parent(可能不是top-most)frame/window:
try { window.parent.location.href } catch(e) {
// Exception was thrown meaning you do not have access to the parent window/frame!
}
我正在尝试创建一个投放灯箱的广告,但广告本身将被放置在注入网站的 iframe and/or 中(不同的域).有些站点会将它放在 iframe 中,而有些则按原样放在站点上。我将无法控制要放置广告的网站。
我知道我可以使用 postMessage()
从 iframe 中发送数据并使用接收到的数据在父级 window 上执行命令,但我不能在父级上放置任何代码window。是否有适用于两种场景的通用解决方案?我想推送一些内容给父级 window.
这段代码完全符合我的要求,但我不知道它是如何做到的:
<script src="http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=rsb&c=28&pli=17085731&PluID=0&w=1&h=1&ord=[timestamp]&ucm=true&ncu=$$%c$$"></script>
<noscript>
<a href="%chttp%3A//bs.serving-sys.com/BurstingPipe/adServer.bs%3Fcn%3Dbrd%26FlightID%3D17085731%26Page%3D%26PluID%3D0%26Pos%3D67849382" target="_blank"><img src="%%VIEW_URL_ESC%%.http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=bsr&FlightID=17085731&Page=&PluID=0&Pos=67849382" border=0 width=1 height=1></a>
</noscript>
如果代码在 frame/iframe 中并且您无权访问 parent frame/window 并且 parent frame/window 没有 API 通过 postMessage()
设置加载 pop-over/lightbox 那么答案是否定的。
您唯一可以执行此操作的情况是使用友好的 iFrame(与 parent frame/window 相同的域)或采取解决方法以允许访问 parent frame/window。请注意,即使这样做了并且您访问并更改了 parent 如果他们不期望您尝试添加的内容或者您有意或无意地更改,您可能会激怒框架所在网站的发布者或所有者他们的网站或样式表以任何方式或注入可能是恶意的脚本。如果你反复这样做,你也可能会被你发送广告的任何网络禁止。
如果使用 SafeFrame,您将无法做到这一点。 SafeFrame 旨在防止广告商更改顶层 window/frame 它提供了一个 API 来展开广告,如果它是一种可扩展的广告类型,但 SafeFrame API 中没有弹出窗口。
如果您想测试是否可以访问 parent/top frame/window,您可以尝试:
前frame/window:
try { window.top.location.href } catch(e) {
// Exception was thrown meaning you do not have access to the top window/frame!
}
对于parent(可能不是top-most)frame/window:
try { window.parent.location.href } catch(e) {
// Exception was thrown meaning you do not have access to the parent window/frame!
}