Html & Script

jquery iframe 제어하기

페이지 정보

본문

<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)로 변경해도 된다.




출처: http://techno99.tistory.com/639 [셜록홈즈의 시선 (Sight of Sherlock Holmes)]

관련자료

등록된 댓글이 없습니다.
Today's proverb
우리의 꿈은, 뒤에 오는 사람들이 우리를 딛고 우리 위에서 이루게 하는 것입니다. 나는 평생을 창조적인 작업을 위해서 살아왔습니다. 누가 하라고 해서 한 것이 아니라 그것이 나의 삶 그 자체의 즐거움이었기 때문입니다. 현실을 직시하며 현재의 수준을 유지하라. 그리고 더 먼 곳을 향하는 시야를 가져라.