Document.open()

这篇翻译不完整。请帮忙从英语翻译这篇文章

Document.open() 方法打开一个要写入的文档。

句法

document.open();

例子

/*
在本示例中,当文档在open()上重新初始化时,文档内容将被覆盖。
*/
document.write("<html><p>remove me</p></html>"); 
document.open(); 
// 文件是空的。

注意

如果目标中存在文档,则此方法将清除它(请参见上面的示例)。

此外,当 document.write() 在页面加载后调用,但在W3C规范中没有定义时,会发生自动的 document.open()调用。
document non-spec'ed parameters to document.open

Do not confuse this method with window.open(). document.open allows you to overwrite the current document or append to it, while window.open provides a way to open a new window, leaving the current document intact. Since window is the global object, just calling open(...) does the same as window.open(...).You can close the opened document using document.close().

See Security check basics for more about principals.

规范

Specification Status Comment
Document Object Model (DOM) Level 2 HTML Specification
document.open()
Recommendation Initial definition

浏览器兼容性

  
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
  
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes) ? ? ? ?

Gecko-特定的 注意

Starting with Gecko 1.9, this method is subject to the same same-origin policy as other properties, and does not work if doing so would change the document's origin.

Starting with Gecko 1.9.2, document.open() uses the principal of the document whose URI it uses, instead of fetching the principal off the stack. As a result, you can no longer call document.write() into an untrusted document from chrome, even using wrappedJSObject.

文档标签和贡献者

标签: 
 此页面的贡献者: xgqfrms-GitHub
 最后编辑者: xgqfrms-GitHub,