创建自定义文档对象:

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'


Firefox:

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


为什么自定义文档缺少方法openwriteclose

最佳答案

document.implementation.createDocument返回XMLDocument
但是,.writedocument中的函数inherits HTMLDocument

基本上,XMLDocument没有该功能。
您可能正在寻找createHTMLDocument

关于javascript - 为什么自定义文档对象中缺少document.write?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27423863/

10-11 12:39
查看更多