IT분야 (IT sector)

jquery iframe 제어하기

Sherlockhomes 2015. 6. 4. 20:47
728x90

 

 

<body>

  <iframe id=“iframeTest” src=“test.html”></iframe>

</body>

 

 

//iframe 접근

window.frames.length; // 1

window.frames[0].document; // iframe의 window의 document객체

document.getElementById('iframeTest’); // iframe 엘리먼트

document.getElementById(‘iframeTest’).contentWindow.document; // iframe의 window의 document객체

 

 

//iframe 새로고침

$('iframe').get(0).contentDocument.location.reload();

 

 

//iframe 로드

$('#iframeTest').load(function(){    //iframe이 모두 load된후 제어

    $(this).contents().find('body');

});

 

 

 

//부모html에서 자식iframe 접근, 제어

$('#iframeTest').contents().find('#foo').text('안녕하세요');

 

 

 

 

//부모html에서 자식iframe 함수 실행

$('#iframeTest').get(0).contentWindow.test(args);

$('#iframeTest')[0].contentWindow.test(args);


//부모html에서 자식iframe 변수접근

$('#iframeTest').get(0).contentWindow.접근할변수명;

 

 

// 자식iframe에서 부모html의 다른 iframe에 접근

$('제어할 아이디', parent.frames["부모창 제어할 frame의 name값"].document).html("여기도 제어한다.");

 

// 자식iframe에서 부모html 접근 (최상위 부모html에 접근된다.)

$('부모창 제어할 아이디', parent.document).contents().find('body').html();

// $('부모창 제어할 아이디', parent.document) -> $('#ID이름',top.document)로 변경해도 된다.

 

 

 

 

 

728x90