Javascript Reference - HTML DOM Dialog open Property








The open property sets or gets whether a dialog is open or not.

This property reflects the <dialog> open attribute.

Browser Support

open Yes 37+ No No Yes 6+ Yes 24+

Syntax

Return the open property:

var v = dialogObject.open

Set the open property:

dialogObject.open=true|false

Property Values

Value Description
true|false  Specifies whether a dialog window is open or not




Return Value

A Boolean type, true if the dialog window is open, otherwise it returns false.

Example

The following code shows how to open a dialog window.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<dialog id="myDialog">This is an open dialog window</dialog>
<!--from w w  w.j av  a 2 s. c  om-->
<script>
function myFunction() {
    document.getElementById("myDialog").open = true;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to find out if a dialog window is open or not.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w  ww .  jav  a2  s. co  m-->
<dialog id="myDialog" open>This is an open dialog window</dialog>

<script>
function myFunction() {
    var x = document.getElementById("myDialog").open;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: