Close a dialog window:
Click the buttons to show or close the 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> <script> var x = document.getElementById("myDialog"); function showDialog() {//from w ww. ja va 2 s .c om x.show(); } function closeDialog() { x.close(); } </script> </body> </html>
The close()
method closes the dialog.