Reputation: 3871
Is there a way to check if a <dialog>
is open using javascript? For example using dialogId.isOpen()
function ?
Upvotes: 7
Views: 7388
Reputation: 24383
The HTMLDialogElement has the property open
, which is a boolean whether the dialog is open or not.
I haven't tested, this, but I would assume you can do:
if (dialogId.open) {
// do something
} else {
// dialog is closed
}
Upvotes: 9
Reputation: 315
You can add an ID to the dialog and access it's open value using DOM like:
<dialog id="myDialog">This is an open dialog window</dialog>
<script>
function myFunction() {
console.log(document.getElementById("myDialog").open);
}
</script>
Upvotes: 1
Reputation: 71
Use the .open
property.
if (dialogElement.open) {
// ...
}
More: https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/open
Upvotes: 3
Reputation: 482
I generally use a jQuery UI dialog.
$('#dialog').dialog('isOpen')
Upvotes: -1