Javascript Reference - HTML DOM Dialog showModal() Method








The showModal() method shows the dialog.

Browser Support

showModal Yes 37+ No No Yes 6+ Yes 24+

Syntax

dialogObject.showModal() 

Example

The following code shows how to show a dialog window.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Show dialog</button>
<dialog id="myDialog">This is a dialog window</dialog>
<!--   w  ww  . j a v a2s  .  co  m-->
<script>
function myFunction() { 
    document.getElementById("myDialog").showModal(); 
} 
</script>

</body>
</html>

The code above is rendered as follows: