맛집 여행 캠핑 일상 생활

[자바스크립트] 자식 iframe load 후 접근하기 본문

JAVASCRIPT

[자바스크립트] 자식 iframe load 후 접근하기

영은파더♥ 2018. 9. 18. 10:08

[자바스크립트] 자식 iframe load 후 접근하기


자식에서 부모의 element를 접근할 때는 parent.$('#elementID') 이렇게 하면 됩니다.


▶ iframe load 이벤트

var o_frame = document.getElementById('프레임ID');

$(o_frame).load(function(){

console.log('iframe onload');

});


부모에서 자식의 iframe 안에 있는 엘리먼트 접근은 아래 처럼 하면 됩니다.

var o_frame = document.getElementById('프레임ID');

$(o_frame).load(function(){

var cFrame = this.contentDocument;

$('#엘리먼트ID', cFrame).hide();

console.log('iframe body height : ' + $('body', cFrame).height() );

});

$(this.contentDocument).contents().find('body').height()

형태로도 가능합니다.


Trackback : | Comments :