js

iframe 내 element id 접근하기

하나에하나 2009. 5. 13. 15:40

현재 윈도우에 iframe을 작업하고 iframe내 요소에 접근하기 위해서는

 

document.getElementById('iframe_id').contentWindow.document.getElementById("element_id")

 

와 같이 contentWindow로 iframe의 윈도우를 지정해 주어야합니다

 


contentWindow


The contentWindow property returns the window object for the frame.

Syntax

frameWindow = frameElement.contentWindow
 

Parameters

frameWindow is an object reference to the window object for this frame.

Example

f = document.getElementById("frame");
 
f.contentWindow.location = "http://mozilla.org";
 
f.contentWindow.history.back();
 

Notes

You can also get to the window object through a named frame. For example, a frame with the name="myFrame" can refer back to the window object as window.frames["myFrame"].

Specification

DOM Level 2 -- HTMLFrameElement