How to tell if any jquery dialog happens to be open? [duplicate]
Asked Answered
T

5

20

Looking for a general case solution to determine if any jquery dialog (there are multiple) is currently open. Have tried:

$(".ui-dialog-content").dialog("isOpen") === true
$(".ui-dialog").dialog("isOpen") == true
$(document).dialog("isOpen") == true
$("*").dialog('isOpen') == true

without any success. I expected ".ui-dialog-content" to work, since I can apparently close any open dialog with that selector, but it does not.

Tripe answered 3/2, 2012 at 14:52 Comment(0)
S
32

you can try

if($(".ui-dialog").is(":visible")){
//dialog is open
}
Synchro answered 3/2, 2012 at 14:59 Comment(2)
Something must be really odd with the styles on this page then. In firebug console while a dialog is open: $('.ui-dialog').is("visible") == falseTripe
@Tripe - note the colon in front of :visible - it's a psuedo-selector.Betteann
E
2

jQuery UI dailog has a method isOpen which returns true if the dailog is open. Call it on the element which has opened the dialog box.

$('.ui-dialog-content').dialog("isOpen");

Refrence: http://jqueryui.com/demos/dialog/#method-isOpen

Eckardt answered 3/2, 2012 at 14:58 Comment(3)
see my question - $('.ui-dialog-content').dialog("isOpen") returns false while a dialog is open.Tripe
tried this - only works for the first dialog in the class. You'd need to use .each() to check for any dialog.Betteann
I think that should have taken care by dialog to run each loop internally.Eckardt
F
1

According to the API documentation, you should use

$( ".selector" ).dialog( "isOpen" )

to determine whether the dialog is open or not. The function returns a boolean. For example,

if( $("selector").dialog("isOpen")===true ){
     /*do stuff when dialog is open*/
} else {
     /*do stuff when dialog is closed*/
};
Finish answered 6/4, 2015 at 16:22 Comment(0)
S
0

Check if it's being displayed or not via CSS? Not sure if it's the right approach, but I suspect it'll work.

$(".ui-dialog").css('display') != "none"
Sheelah answered 3/2, 2012 at 14:56 Comment(3)
EDIT: actually $(".ui-dialog-content").css('display') != "none" gives a false positive if the dialog is closed, but does return true when it's open, while ".ui-dialog" seems to be always false.Tripe
>>> $(".ui-dialog-content").css('display') "block" >>> $(".ui-dialog").css('display') "none" regardless of dialog state, in firefox at least.Tripe
yeah it was a shot in the dark, I haven't used ui-dialog, was going off my general knowledge, looks like you found your answer though so that's great!Sheelah
H
-1
$('html').click(function() {
    x++;
    if(x==2){
    $(".ui-dialog-titlebar-close").trigger("click");
    x=0;
    }
    });

This one will work in all cases, where you call Dialog from DOM.

Hundredweight answered 3/4, 2015 at 14:4 Comment(1)
Not answering the qtnBrochu

© 2022 - 2024 — McMap. All rights reserved.