简体   繁体   English

插页式广告(异步广告),无需在网站上放置任何代码

[英]Interstitial ads (asynchronous ads) without placing any code on the website

I am trying to create an ad which throws a lightbox, but the ad itself is going to be placed either inside an iframe and/or injected to the site ( not the same domain ). 我正在尝试创建一个投放灯箱的广告,但该广告本身将放置在iframe中和/或注入到网站( 不是同一域 )中。 Some sites will have it inside an iframe and some just on the site as is. 有些网站会将其放置在iframe中,有些则原样放置在该网站上。 I will not have control over the site where the ad is going to be placed. 我将无法控制将要放置广告的网站。

I know I can use the postMessage() to send data from within the iframe and do commands on the parent window with the received data, but I can't place any code on the parent window. 我知道我可以使用postMessage()从iframe中发送数据,并使用接收到的数据在父窗口上执行命令,但是我不能在父窗口上放置任何代码。 Is there a universal solution that works in both scenerios? 有两种场景都适用的通用解决方案吗? I want to push some contents to the parent window. 我想将一些内容推送到父窗口。

This code does exactly what I am asking, but I don't know how it's doing it: 这段代码完全符合我的要求,但是我不知道它是如何做到的:

<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>

If the code is inside a frame/iframe and you do not have access to the parent frame/window and the parent frame/window has no API setup via postMessage() to load pop-over/lightbox then the answer is no. 如果代码在框架/ iframe中,并且您无权访问父框架/窗口,并且父框架/窗口没有通过postMessage()设置API来加载弹出窗口/灯箱,那么答案是否定的。

The only time you could do this is when a friendly iFrame (same domain as parent frame/window) is used or a workaround is done to allow access to the parent frame/window. 唯一可以执行此操作的时间是使用友好的iFrame(与父框架/窗口相同的域)或执行变通办法以允许访问父框架/窗口。 Note that even if this is done and you access and alter the parent you may anger the publisher or owner of the site the frame is on if they are not expecting what you are trying to add or if you intentionally or unintentionally alter their site or stylesheet in any way or inject scripts that may be malicious. 请注意,即使这样做已经完成,并且您访问并更改了父级,也可能激怒该框架所在的发布者或网站所有者,如果他们不希望您尝试添加的内容,或者您​​有意或无意地更改了他们的网站或样式表以任何方式注入恶意脚本。 If you do that repeatedly you may also get banned by any networks you are sending your ads through. 如果您重复执行此操作,那么您通过其发送广告的任何网络也可能会禁止该广告。

If SafeFrame is used you will not be able to do that. 如果使用SafeFrame,则将无法执行此操作。 SafeFrame is designed to prevent advertisers from altering the top level window/frame it provides an API to expand the ad if it is an expandable ad type but there is no popover in the SafeFrame API. SafeFrame旨在防止广告客户更改顶级窗口/框架,如果广告是可扩展的广告类型,但SafeFrame API中没有弹出窗口,它会提供API来扩展广告。

If you wish to test if you have access to the parent/top frame/window you can try: 如果您想测试是否可以访问父级/顶部框架/窗口,可以尝试:

For top frame/window: 对于顶部框架/窗口:

try { window.top.location.href } catch(e) {
    // Exception was thrown meaning you do not have access to the top window/frame!
}

For parent (may not be the 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!
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM