Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 649177 of HTMLDialogElement

  • Revision slug: Web/API/HTMLDialogElement
  • Revision title: HTMLDialogElement
  • Revision id: 649177
  • Created:
  • Creator: dhodder
  • Is current revision? No
  • Comment Add entry for HTMLDialogElement

Revision Content

{{ DomRef() }}

{{ SeeCompatTable() }}

The HTMLDialogElement interface provides methods to manipulate {{HTMLElement("dialog")}} elements. It inherits properties and methods from the {{domxref("HTMLElement")}} interface.

Properties

Inherits properties from its parent, {{domxref("HTMLElement")}}.

Name Type Description
open {{domxref("Boolean")}} Reflects the {{ htmlattrxref("open", "dialog") }} HTML attribute, indicating that the dialog is available for interaction.
returnValue {{domxref("DOMString")}} Gets/sets the return value for the dialog.

Methods

Inherits methods from its parent, {{domxref("HTMLElement")}}.

Name & Arguments Return Description
close() {{ HTMLVersionInline(5) }} void Closes the dialog. An optional {{domxref("DOMString")}} may be passed as an argument, updating the returnValue of the the dialog.
show() {{ HTMLVersionInline(5) }} void Displays the dialog modelessly, i.e. still allowing interaction with content outside of the dialog. An optional {{domxref("Element")}} or {{domxref("MouseEvent")}} may be passed as an argument, to specify an anchor point to which the dialog is fixed.
showModal() {{ HTMLVersionInline(5) }} void Displays the dialog for exclusive interaction, over the top of any other dialogs that might be present. An optional {{domxref("Element")}} or {{domxref("MouseEvent")}} may be passed as an argument, to specify an anchor point to which the dialog is fixed.

Examples

Example 1

<dialog open>
  <p>Greetings, one and all!</p>
</dialog>

Example 2

<!-- Simple pop-up dialog box, containing a form -->
<dialog id="favDialog">
  <form method="dialog">
    <section>
      <p><label for="favAnimal">Favorite animal:</label>
      <select id="favAnimal" name="favAnimal">
        <option></option>
        <option>Brine shrimp</option>
        <option>Red panda</option>
        <option>Spider monkey</option>
      </select></p>
    </section>
    <menu>
      <button id="cancel" type="reset">Cancel</button>
      <button type="submit">Confirm</button>
    </menu>
  </form>
</dialog>

<menu>
  <button id="updateDetails">Update details</button>
</menu>

<script>
  (function() {
    var updateButton = document.getElementById('updateDetails');
    var cancelButton = document.getElementById('cancel');

    // Update button opens a modal dialog
    updateButton.addEventListener('click', function() {
      document.getElementById('favDialog').showModal();
    });

    // Form cancel button closes the dialog box
    cancelButton.addEventListener('click', function() {
      document.getElementById('favDialog').close();
    });

  })();
</script>

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'forms.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML5.1')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 37 {{CompatNo()}} {{bug(840640)}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}
Anchor points {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}
Anchor points {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}

See also

  • The HTML element implementing this interface: {{ HTMLElement("dialog") }}.

Revision Source

<p>{{ DomRef() }}</p>
<p>{{ SeeCompatTable() }}</p>
<p>The <strong><code>HTMLDialogElement</code></strong> interface provides methods to manipulate {{HTMLElement("dialog")}} elements. It inherits properties and methods from the {{domxref("HTMLElement")}} interface.</p>
<h2 id="Properties">Properties</h2>
<p><em>Inherits properties from its parent, {{domxref("HTMLElement")}}.</em></p>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Name</th>
   <th scope="col">Type</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>open</code></td>
   <td>{{domxref("Boolean")}}</td>
   <td>Reflects the {{ htmlattrxref("open", "dialog") }} HTML attribute, indicating that the dialog is available for interaction.</td>
  </tr>
  <tr>
   <td><code>returnValue</code></td>
   <td>{{domxref("DOMString")}}</td>
   <td>Gets/sets the return value for the dialog.</td>
  </tr>
 </tbody>
</table>
<h2 id="Methods">Methods</h2>
<p><em>Inherits methods from its parent, {{domxref("HTMLElement")}}.</em></p>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Name &amp;&nbsp;Arguments</th>
   <th scope="col">Return</th>
   <th scope="col">Description</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>close()</code> {{ HTMLVersionInline(5) }}</td>
   <td><code>void</code></td>
   <td>Closes the dialog. An optional {{domxref("DOMString")}} may be passed as an argument, updating the <code>returnValue</code> of the the dialog.</td>
  </tr>
  <tr>
   <td><code>show()</code> {{ HTMLVersionInline(5) }}</td>
   <td><code>void</code></td>
   <td>Displays the dialog modelessly, i.e. still allowing interaction with content outside of the dialog. An optional {{domxref("Element")}} or {{domxref("MouseEvent")}} may be passed as an argument, to specify an anchor point to which the dialog is fixed.</td>
  </tr>
  <tr>
   <td><code>showModal()</code> {{ HTMLVersionInline(5) }}</td>
   <td><code>void</code></td>
   <td>Displays the dialog for exclusive interaction, over the top of any other dialogs that might be present. An optional {{domxref("Element")}} or {{domxref("MouseEvent")}} may be passed as an argument, to specify an anchor point to which the dialog is fixed.</td>
  </tr>
 </tbody>
</table>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example_1">Example 1</h3>
<pre class="brush: html">
&lt;dialog open&gt;
  &lt;p&gt;Greetings, one and all!&lt;/p&gt;
&lt;/dialog&gt;
</pre>
<h3 id="Example_2">Example 2</h3>
<pre class="brush: html">
&lt;!-- Simple pop-up dialog box, containing a form --&gt;
&lt;dialog id="favDialog"&gt;
  &lt;form method="dialog"&gt;
    &lt;section&gt;
      &lt;p&gt;&lt;label for="favAnimal"&gt;Favorite animal:&lt;/label&gt;
      &lt;select id="favAnimal" name="favAnimal"&gt;
        &lt;option&gt;&lt;/option&gt;
        &lt;option&gt;Brine shrimp&lt;/option&gt;
        &lt;option&gt;Red panda&lt;/option&gt;
        &lt;option&gt;Spider monkey&lt;/option&gt;
      &lt;/select&gt;&lt;/p&gt;
    &lt;/section&gt;
    &lt;menu&gt;
      &lt;button id="cancel" type="reset"&gt;Cancel&lt;/button&gt;
      &lt;button type="submit"&gt;Confirm&lt;/button&gt;
    &lt;/menu&gt;
  &lt;/form&gt;
&lt;/dialog&gt;

&lt;menu&gt;
  &lt;button id="updateDetails"&gt;Update details&lt;/button&gt;
&lt;/menu&gt;

&lt;script&gt;
  (function() {
    var updateButton = document.getElementById('updateDetails');
    var cancelButton = document.getElementById('cancel');

    // Update button opens a modal dialog
    updateButton.addEventListener('click', function() {
      document.getElementById('favDialog').showModal();
    });

    // Form cancel button closes the dialog box
    cancelButton.addEventListener('click', function() {
      document.getElementById('favDialog').close();
    });

  })();
&lt;/script&gt;
</pre>
<h2 id="Specifications" name="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', 'forms.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
   <td>{{Spec2('HTML5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>37</td>
    <td>{{CompatNo()}} {{bug(840640)}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
   <tr>
    <td>Anchor points</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
   <tr>
    <td>Anchor points</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
 <li>The HTML element implementing this interface: {{ HTMLElement("dialog") }}.</li>
</ul>
Revert to this revision