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
이것이 바로 나의 생각이다. 하고 제대로 내놓고 말할 수 있는 자기 나름의 생각을 갖는 데는 10년이 걸린다. (A. 카뮈)