/
creative.html
38 lines (34 loc) · 1.16 KB
/
creative.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!-- This script tag should be returned by your ad server -->
<script>
// This is the `renderAd` function from Prebid.js moved within the creative iframe
var renderAd = function (ev) {
var key = ev.message ? "message" : "data";
var data = {};
try {
data = JSON.parse(ev[key]);
} catch (e) {
// Do nothing. No ad found.
}
if (data.ad || data.adUrl) {
if (data.ad) {
document.write(data.ad);
document.close();
} else if (data.adUrl) {
document.write('<IFRAME SRC="' + data.adUrl + '" WIDTH="'+ data.width +'" HEIGHT="'+ data.height +'" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true"></IFRAME>');
document.close();
}
}
};
var requestAdFromPrebid = function () {
var message = JSON.stringify({
message: 'Prebid creative requested: %%PATTERN:hb_adid%%',
adId: '%%PATTERN:hb_adid%%'
});
window.parent.postMessage(message, '*');
};
var listenAdFromPrebid = function () {
window.addEventListener("message", renderAd, false);
};
listenAdFromPrebid();
requestAdFromPrebid();
</script>