본문 바로가기
Javascript

iframe document.write vs innerHTML

by GoodDev 2018. 1. 3.

iframe 내부의 javascript 가 로딩시에 구동되지 않는 현상이 있어서 처리 방법에 대해서 추가한다.


iframe.contentDocument.write 시에 open , close 로 클로징해야 하며 이를 사용시에는 javacript 가 구동된다.


innerHTML 을 사용할 경우 수행되지 않는다.



firefox 의 경우 innerHTML 이 작동하지 않을 경우 


var _GOODDEV_IFRAME = document.getElementById('iframe ID명');

var _GOODDEV_IFRAME_DOC = _GOODDEV_IFRAME.contentWindow || ( _GOODDEV_IFRAME.contentDocument.document || _GOODDEV_IFRAME.contentDocument);


// 하단 라인을 입력한 후 innerHTML 을 수행한다.

_GOODDEV_IFRAME_DOC.document.open();

_GOODDEV_IFRAME_DOC.document.close();


참고 바랍니다.

댓글