Table of Contents

HTML - Dialog

About

A dialog in HTML represents a part of an application that a user interacts with to perform a task

For example:

Example

<dialog id="ship">
 <form method=dialog>
  <p>A ship has arrived in the harbour.</p>
  <button type=submit value="board">Board the ship</button>
  <button type=submit value="call">Call to the captain</button>
 </form>
</dialog>
var ship = document.getElementById('ship');
ship.showModal();
ship.onclose = function (event) {
    if (ship.returnValue == 'board') {
       console.log("Board the ship");
   } else {
       console.log("Call the capitain");
   }
 };

Syntax

<dialog open>
</dialog>
// Displays the dialog element.
dialog.show()
// Displays the dialog element and makes it the top-most modal dialog.
// This method honors the autofocus attribute.
dialog.showModal()
// Closes the dialog element.
// The argument, if provided, provides a return value.
dialog.close([ result ])
// Returns the dialog's return value.
// Can be set, to update the return value.
dialog.returnValue [ = result ]

Documentation / Reference