HTML DOM IFrame Object 살펴보기, contentDocument, contentWindow
1. IFrame Object
IFrame Object 는 HTML 의 <iframe> 엘리먼트를 나타내는 것이다.
아래와 같이 getElementById() 함수를 이용하여 접근할 수 있다.
var x = document.getElementById("myFrame");
아래와 같이 생성하여 특정 DIV 에 넣을 수도 있다.
var x = document.createElement("IFRAME");
2. IFrame 속성
contentDocument : IFrame 에 의해 생성된 document 객체이다.
contentWindow : IFrame 에 의해 생성된 window 객체이다
기타 속성과 예제는 다음 링크를 참고하면 된다.
http://www.w3schools.com/jsref/dom_obj_frame.asp
3. 실전예제
sData 를 받아서, IFrame 을 생성한 다음에 resultbox DIV 에 IFrame 을 넣는 함수
function PushDataToFrame(sData)
{
var ifr = document.createElement("iframe");
ifr.setAttribute("frameborder", "0");
ifr.setAttribute("width", "100%");
ifr.setAttribute("height", "100%");
ifr.setAttribute("id", "iframeResult");
document.getElementById("resultbox").innerHTML = "";
document.getElementById("resultbox").appendChild(ifr);
var ifrw = (ifr.contentWindow) ? ifr.contentWindow : (ifr.contentDocument.document) ? ifr.contentDocument.document : ifr.contentDocument;
ifrw.document.open();
ifrw.document.write(sData);
ifrw.document.close();
}