aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/document/abrir/index.html
blob: 13b541561dc76bfe74501a0c8712a3f4411fa871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
title: Document.open()
slug: Web/API/Document/abrir
translation_of: Web/API/Document/open
---
<div>{{APIRef("DOM")}}</div>

<p>El método <strong><code>Document.open()</code></strong> abre un documento para escritura (<a href="/en-US/docs/Web/API/Document/write" title="en/DOM/document.write">writing</a>)</p>

<p>Esto viene con algunos efectos secundarios. Por ejemplo:</p>

<ul>
 <li>Todos las atenciones de eventos actualmente registrados en el documento, los nodos dentro del documento o la ventana del documento son eliminados.</li>
 <li>Todos los nodos existentes se eliminan del documento.</li>
</ul>

<h2 id="Syntax" name="Syntax">Sintaxis</h2>

<pre class="syntaxbox notranslate">document.open();
</pre>

<h3 id="Parametros">Parametros</h3>

<p>Ninguno.</p>

<h3 id="Valor_devuelto">Valor devuelto</h3>

<p>Una instancia del objeto Document (<code>Document)</code>.</p>

<h2 id="Example" name="Example">Ejemplos</h2>

<p>El código simple a continuación abre el documento y reemplaza su contenido con un número de diferentes fragmentos HTML antes de cerrarlo nuevamente.</p>

<pre class="notranslate">document.open();
document.write("&lt;p&gt;Hola mundo!&lt;/p&gt;");
document.write("&lt;p&gt;Soy un pez&lt;/p&gt;");
document.write("&lt;p&gt;El numero es 42&lt;/p&gt;");
document.close();</pre>

<h2 id="Notes" name="Notes">Notas</h2>

<div class="blockIndicator note">
<p>Traducción pendiente para el texto que sigue</p>
</div>

<p>An automatic <code>document.open()</code> call happens when {{domxref("document.write()")}} is called after the page has loaded.</p>

<p>For years Firefox and Internet Explorer additionally erased all JavaScript variables, etc., in addition to removing all nodes. This is no longer the case.<span class="comment">document non-spec'ed parameters to document.open</span></p>

<h3 id="Gecko-specific_notes">Gecko-specific notes</h3>

<p>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.</p>

<p>Starting with Gecko 1.9.2, <code>document.open()</code> uses the <a href="/docs/Security_check_basics">principal</a> of the document whose URI it uses, instead of fetching the principal off the stack. As a result, you can no longer call {{domxref("document.write()")}} into an untrusted document from chrome, even using <a class="internal" href="/en/wrappedJSObject"><code>wrappedJSObject</code></a>. See <a href="/en/Security_check_basics" title="en/Security check basics">Security check basics</a> for more about principals.</p>

<h2 id="Example" name="Example">Three-argument document.open()</h2>

<p>There is a lesser-known and little-used three-argument version of <code>document.open()</code> , which is an alias of {{domxref("Window.open()")}} (see its page for full details).</p>

<p>This call, for example opens github.com in a new window, with its opener set to <code>null</code>:</p>

<pre class="brush: js notranslate"><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body"><span class="cm-variable">document</span>.<span class="cm-property">open</span>(<span class="cm-string">'https://www.github.com'</span>,<span class="cm-string">''</span>, <span class="cm-string">'noopener=true'</span>)</span></span></span></pre>

<h2 id="Two-argument_document.open"><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">Two-argument document.open()</span></span></span></h2>

<p><span class="message-body-wrapper"><span class="message-flex-body"><span class="devtools-monospace message-body">Browsers used to support a two-argument <code>document.open()</code>, with the following signature:</span></span></span></p>

<pre class="brush: js notranslate">document.open(<em>type</em>, <em>replace</em>)</pre>

<p>Where <code>type</code> specified the MIME type of the data you are writing (e.g. <code>text/html</code>) and replace if set (i.e. a string of <code>"replace"</code>) specified that the history entry for the new document would replace the current history entry of the document being written to.</p>

<p>This form is now obsolete; it won't throw an error, but instead just forwards to <code>document.open()</code> (i.e. is the equivalent of just running it with no arguments).  The history-replacement behavior now always happens.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("HTML WHATWG", "#dom-document-open", "document.open()")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("DOM2 HTML", "html.html#ID-72161170", "document.open()")}}</td>
   <td>{{Spec2("DOM2 HTML")}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.Document.open")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Document")}}</li>
 <li>{{domxref("Window.open()")}}</li>
</ul>