如何在窗口中替换文档? [英] How do you replace the document in a window?

查看:81
本文介绍了如何在窗口中替换文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var newDoc = document.implementation.createHTMLDocument('someTitle');
// swap newDoc with document

DOMImplementation.createHTMLDocument

  • 是否可以将当前文档替换为新文档?
  • 是否有合理的理由这样做?

推荐答案

您不能将当前文档对象或任何文档对象替换为使用 createHTMLDocument 方法创建的 Document 对象

You cannot replace the current document object or any document object with the Document object created with createHTMLDocument method.

createHTMLDocument 最初是在 DOM Level 2核心的草案之一中引入的,但后来被从最终推荐中删除.

The createHTMLDocument was first introduced in one of the drafts of the DOM Level 2 Core, but was later removed from the final recommendation.

由于没有编程方式来创建HTML文档,因此后来将其添加到HTML5规范中.

It was later added to the HTML5 spec as there was no programmatic way to create an HTML document.

通过编程创建HTML文档提供的一些用例是

Some of the use cases provided for programmatic creation of an HTML document were,

  • 创建一个未渲染的HTML文档,以通过XMLHttpRequest上传(而不是通过发送XML文档).

  • Create a non-rendered HTML document to upload via XMLHttpRequest (instead of sending an XML document).

以一定的方式对库代码中的HTML DOM进行功能测试避免对显示的文档产生副作用.

Feature-test the HTML DOM in library code in a way that is guaranteed to avoid side effects on the displayed document.

从RTF编辑区域创建隔离的未渲染文档,因此可以在上传之前完成客户端清理,而不会影响实时运行用户仍然可以进一步编辑的DOM.

Create an isolated non-rendered document from a rich text editing area, so client-side cleanup can be done before uploading without disturbing the live DOM that the user may still edit further.

在JavaScript中实现HTML5解析算法客户端的测试和比较目的,或用于虚拟化或基于对象功能的安全性.

Implement HTML5 parsing algorithm client-side in JavaScript for testing and comparison purposes, or for virtualization or object-capability-based security.

不可见的iframe可以用于大多数这些目的,但更多在资源方面很昂贵. W3C邮件列表

An invisible iframe can be used for most of these purposes but that is more expensive in terms of resources. W3C mailing list

有关W3C邮件列表的讨论使该方法重新回到规范中, [错误7842]新增:没有以编程方式制作HTML文档的方法-请考虑添加createHTMLDocument

The conversation on W3C mailing lists that brought the method back into the spec, [Bug 7842] New: No programmatic way to make an HTML document - consider adding createHTMLDocument

这篇关于如何在窗口中替换文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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