创建自定义文档对象:
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
。我勒个去?这是一个错误吗?可能不是 - 所有浏览器都这样做:
Chrome (有史以来最糟糕的错误,Chrome调试必须很有趣):
Uncaught TypeError: undefined is not a function
歌剧:
TypeError: Object #<Document> has no method 'write'
火狐:
TypeError: document.implementation.createDocument(...).write is not a function
为什么自定义文档缺少方法open
,write
和close
?
答案 0 :(得分:3)
document.implementation.createDocument
返回XMLDocument
但是,.write
是来自document
的inherits HTMLDocument
函数。
基本上,XMLDocument
没有这个功能
你可能正在寻找createHTMLDocument