マイ備忘録

あくまで個人の意見、メモです。

friendly iframe

friendly iframeとは

A Friendly IFrame is an IFrame that shares the same domain as the main page it is hosted on. This generally means that the content is trusted and hence, >can ‘break out’ of the IFrame and manipulate the content on the hosting page. Friendly IFrame is some kind of interactive and communicating frame.

Adform | Friendly and non-Friendly IFrames

とのことで、親ページと同じオリジンのiframe。これはsrcを指定しないでiframeを作ると勝手にそうなる。

同じくadformより。

How to recognize a friendly ifame? Usually it’s source attribute ‘src’ is set to a small advertisement page file in the same domain as the page or ‘src’ is set to “about:self”.

about:selfはwebkitだとエラーになる(ソースちら見したらemptyかabout:blankのみ)ので、srcには何も指定しないのが無難。

friendly iframeは親とオリジンが同じなので、iframeの中からiframe自体にアクセスができる。 friendly iframeに対応しているかどうかはInDapIFという変数を定義するようにとIABからのお達しがあるので、これを使って↓みたいなことができる。

if(typeof inDapIF !== "undefined" && inDapIF === true){
    var w = window.parent.screen.width;
    var iframe = window.parent.document.getElementsByTagName('iframe')[0];
    iframe.style.width = w + 'px';
}

// ここから広告表示
document.write('<div style="width:100%;height:100%;background-color:#000;"><div>');

iframe配下に書き出させる広告scriptのイメージ。こんなコードは使えないけど。

friendly iframeに対応していればiframeの横幅をmaxにして広告表示できる。 CORSとかどうなんだろって思ってたけど、結局サーバ側の設定だからあまりfriendly iframeとは関連がない。