2014-12-11 1 views
2

는 사용자 지정 문서 객체를 생성 : 거기에 쓸 수사용자 정의 문서 객체에 document.write가없는 이유는 무엇입니까?

var doc = document.implementation.createDocument(
    'http://www.w3.org/1999/xhtml', 
    'html', 
    //Inherit current doctype 
    document.doctype 
); 

시도 :

//Throws error - TypeError: doc.write is not a function 
doc.write(document.documentElement.innerHTML); 

같은 .close.open도 마찬가지입니다. 도대체 뭐야? 이거 버그 야? 아마 아닐 - 모든 브라우저가 그것을 :

(대부분의 helful 오류 적, 크롬에서 디버깅하는 재미 있어야합니다)

크롬 :

Uncaught TypeError: undefined is not a function 

오페라 :

TypeError: Object #<Document> has no method 'write' 

파이어 폭스 :

TypeError: document.implementation.createDocument(...).write is not a function 

왜 사용자 정의 문서에 대해 open, writeclose이 누락 되었습니까?

+3

'.write','.open' 및'.close'는 끔찍한 방법이고 사용하면 안되기 때문에 제 추측이 될 것 같습니까? –

+0

실제로 그'doc'로 무엇을하려합니까? – Cerbrus

+0

@NiettheDarkAbsol 왜 그들은 끔찍한가요? 전체 문제에 대해 더 나은 해결책을 제안합니까? –

답변

3

document.implementation.createDocumentXMLDocument을 반환합니다.
그러나, .writedocumentinherits이고, HTMLDocument이다.

기본적으로 XMLDocument에는 해당 기능이 없습니다.
아마도 당신이 찾고 있어요 createHTMLDocument

+0

그럼 HTMLDocument를 정말 만들고 싶습니다. –

+0

['createHTMLDocument'] (https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument) – Cerbrus

+0

MDN에 따르면'XMLDocument'는'Document'를 상속받습니다. '.write' 등이 있습니다. –

관련 문제