创建一个javascript文档对象 [英] create a javascript document Object

查看:106
本文介绍了创建一个javascript文档对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过调用函数来创建或重新创建javascript文档Object。类似

Is there any way to create or recreate a javascript document Object by calling a function. Something like

<script type="javascript/text">
  var document = createDocument("some html");
</script>

我想这样做,所以我可以在这个问题中解决问题在Firefox中使用javascript的客户端xslt

I want to do this so I can solve the issue in this question client side xslt with javascript in firefox

推荐答案

Webkit是第一个为该任务包含/公开以下方法的人:

Webkit was the first to include/expose the following method for that task:

document.implementation.createHTMLDocument(title);

Firefox 4(版本4)也实现了此方法,而对于以前的版本,可以创建HTML文档使用以下内容:

Firefox, from version 4, also implements this method while for previous versions it is possible to create an HTML document using the following:

var doc = document.implementation.createDocument('', '',
  document.implementation.createDocumentType('html', '', ''));

这应该大致相当于具有<!DOCTYPE html>的文档。 (HTML5)。

which should be roughly equivalent to a document having <!DOCTYPE html> (HTML5).

用所需的publicId / systemId替换'createDocumentType'的空字符串。

Replace the empty strings of 'createDocumentType' with the needed publicId/systemId.

仍然需要在生成的文档中创建/附加html,head和body元素以使其具有可用的DOM。

It will be still necessary to create/append html, head and body elements to the resulting document to have a working DOM.

这篇关于创建一个javascript文档对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆