aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/opendialog/index.html
blob: 80705cd7aa8e82150e428bf397ab0b9d2ad7a87f (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
---
title: window.openDialog
slug: Web/API/Window/openDialog
tags:
  - Gecko DOM Reference
translation_of: Web/API/Window/openDialog
---
<p>{{ ApiRef() }}</p>
<h3 id=".E7.AE.80.E4.BB.8B" name=".E7.AE.80.E4.BB.8B">简介</h3>
<p><code>window.openDialog</code> 是对<a href="cn/DOM/window.open">window.open</a>的扩展。和它一样,可以传递<code>windowFeatures</code>参数, 但是 <code>windowFeatures</code> 的方式有变化。</p>
<p>The optional parameters, if present, will be bundled up in a JavaScript Array object and added to the newly created window as a property named <a href="cn/DOM/window.arguments">window.arguments</a>. They may be referenced in the JavaScript of the window at any time, including during the execution of a <code>load</code> handler. These parameters may be used, then, to pass arguments to and from the dialog window.</p>
<p>Note that the call to <code>openDialog()</code> returns immediately. If you want the call to block until the user has closed the dialog, supply <code>modal</code> as a <code>windowFeatures</code> parameter. Note that this also means the user won't be able to interact with the opener window until he closes the modal dialog.</p>
<h3 id=".E8.AF.AD.E6.B3.95" name=".E8.AF.AD.E6.B3.95">语法</h3>
<pre class="eval"><i>newWindow</i> = openDialog(<i>url</i>,<i>name</i>,<i>features</i>,<i>arg1</i>,<i>arg2</i>, ...)
</pre>
<dl>
 <dt>
  newWindow </dt>
 <dd>
  打开的窗口对象。</dd>
 <dt>
  url </dt>
 <dd>
  要在新窗口里打开的地址。</dd>
 <dt>
  name </dt>
 <dd>
  The window name (optional). See <a href="cn/DOM/window.open">window.open</a> description for detailed information.</dd>
 <dt>
  features </dt>
 <dd>
  See <a href="cn/DOM/window.open">window.open</a> description for description.</dd>
 <dt>
  arg1, arg2, ... </dt>
 <dd>
  The arguments to be passed to the new window (optional).</dd>
</dl>
<h3 id=".E4.BE.8B.E5.AD.90" name=".E4.BE.8B.E5.AD.90">例子</h3>
<pre class="eval">var win = openDialog("<span class="nowiki">http://example.tld/zzz.xul</span>", "dlg", "", "pizza", 6.98);
</pre>
<h3 id=".E6.B3.A8.E6.84.8F" name=".E6.B3.A8.E6.84.8F">注意</h3>
<h4 id="New_Features" name="New_Features">New Features</h4>
<p><code>all</code> - Initially activates (or deactivates <code>("all=no")</code>) all chrome (except the behaviour flags <code>chrome</code>, <code>dialog</code> and <code>modal</code>). These can be overridden (so <code>"menubar=no,all"</code> turns on all chrome except the menubar.) This feature is explicitly ignored by <a href="cn/Window.open">window.open</a>. <code>window.openDialog</code> finds it useful because of its different default assumptions.</p>
<h4 id="Default_behaviour" name="Default_behaviour">Default behaviour</h4>
<p>The <code>chrome</code> and <code>dialog</code> features are always assumed on, unless explicitly turned off ("<code>chrome=no</code>"). <code>openDialog</code> treats the absence of the features parameter as does <a href="cn/Window.open">window.open</a>, (that is, an empty string sets all features to off) except <code>chrome</code> and <code>dialog</code>, which default to on. If the <code>features</code> parameter is a zero-length string, or contains only one or more of the behaviour features (<code>chrome</code>, <code>dependent</code>, <code>dialog</code> and <code>modal</code>) the chrome features are assumed "OS' choice." That is, window creation code is not given specific instructions, but is instead allowed to select the chrome that best fits a dialog on that operating system.</p>
<h4 id="Passing_extra_parameters_to_the_dialog" name="Passing_extra_parameters_to_the_dialog">Passing extra parameters to the dialog</h4>
<p>To pass extra parameters into the dialog, you can simply supply them after the &lt;tt&gt;windowFeatures&lt;/tt&gt; parameter:</p>
<pre class="eval">openDialog("<span class="nowiki">http://example.tld/zzz.xul</span>", "dlg", "", "pizza", 6.98);
</pre>
<p>The extra parameters will then get packed into a property named &lt;tt&gt;arguments&lt;/tt&gt; of type <a href="cn/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a>, and this property gets added to the newly opened dialog window.</p>
<p>To access these extra parameters from within dialog code, use the following scheme:</p>
<pre class="eval">var food  = window.arguments[0];
var price = window.arguments[1];
</pre>
<p>Note that you can access this property from within anywhere in the dialog code. (<a href="cn/Code_snippets/Dialogs_and_Prompts#Passing_arguments_and_displaying_a_dialog">Another example</a>).</p>
<h4 id="Returning_values_from_the_dialog" name="Returning_values_from_the_dialog">Returning values from the dialog</h4>
<p>Since &lt;tt&gt;window.close()&lt;/tt&gt; erases all properties associated with the dialog window (i.e. the variables specified in the JavaScript code which gets loaded from the dialog), it is not possible to pass return values back past the close operation using globals (or any other constructs).</p>
<p>To be able to pass values back to the caller, you have to supply some object via the extra parameters. You can then access this object from within the dialog code and set properties on it, containing the values you want to return or preserve past the &lt;tt&gt;window.close()&lt;/tt&gt; operation.</p>
<pre class="eval">var retVals = { address: null, delivery: null };
openDialog("<span class="nowiki">http://example.tld/zzz.xul</span>", "dlg", "modal", "pizza", 6.98, retVals);
</pre>
<p>If you set the properties of the &lt;tt&gt;retVals&lt;/tt&gt; object in the dialog code as described below, you can now access them via the &lt;tt&gt;retVals&lt;/tt&gt; array after the &lt;tt&gt;openDialog()&lt;/tt&gt; call returns.</p>
<p>Inside the dialog code, you can set the properties as follows:</p>
<pre class="eval">var retVals = window.arguments[2];
retVals.address  = enteredAddress;
retVals.delivery = "immediate";
</pre>
<p>See also <a class="external" href="http://groups.google.com/group/netscape.public.dev.xul/msg/02075a1736406b40">. (</a><a href="cn/Code_snippets/Dialogs_and_Prompts#Passing_arguments_and_displaying_a_dialog">Another example</a>).</p>
<h3 id="Specification" name="Specification">Specification</h3>
<p>{{ DOM0() }}</p>
<p>{{ languages( { "pl": "pl/DOM/window.openDialog" } ) }}</p>