개체 요소 (type = "text/html") 안에 document.open/write/close 시퀀스를 호출하려고합니다. Safari/Chrome에서는 contentDocument 특성을 사용하여 내부 문서 객체를 가져올 수 있습니다. 샘플 코드 (jquery 사용) :JavaScript : HTML 개체 태그의 문서 개체를 검색하는 방법은 무엇입니까?
$(document).ready(function() {
var container = $('<object/>')
.css({'width': '700px', 'height': '100px', 'border': '0px none'})
.attr({'type': 'text/html'}).appendTo('body');
var doc = container.get(0).contentDocument;
doc.open();
doc.write('<h1>Hello world!</h1>');
doc.close();
});
다른 브라우저에서 동일한 작업을 수행 할 수있는 방법이 있습니까?
내가 이상한 일을하고 싶은 이유는 DOM을 닫은 후에 document.write를 포함하는 외부 스크립트를 호출해야하기 때문입니다. 이미 iframe을 다루려고했지만 Internet Explorer와 Opera 버그로 인해 실패했습니다. 이 목표를 성취 할 수있는 다른 방법은 인정 될 것입니다.
어떤 버그가 있습니까? 그리고 객체의 src는 원래 같은 출처입니까? – mplungjan
http://stackoverflow.com/questions/1736886/why-wont-this-javascript-using-document-open-and-document-write-work-in-inter Bobince 코멘트는 버그를 설명합니다. IE9는 여전히 영향을 받아 결국 충돌 할 수 있습니다. – pamelus