Javascript Reference - HTML DOM Dialog close() Method








The close() method closes the dialog.

Browser Support

close() Yes 37+ No No Yes 6+ Yes 24+

Syntax

dialogObject.close() 

Example

The following code shows how to show and close a dialog window:


<!DOCTYPE html>
<html>
<body>
<button onclick="showDialog()">Show dialog</button>
<button onclick="closeDialog()">Close dialog</button>
<dialog id="myDialog">This is a dialog window</dialog>
<!-- w w  w. ja  v  a 2 s . c o m-->
<script>
var x = document.getElementById("myDialog"); 

function showDialog() { 
    x.show(); 
} 

function closeDialog() { 
    x.close(); 
} 
</script>

</body>
</html>

The code above is rendered as follows: