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.

lamont
  • 428
  • 1
  • 7
  • 16

5 Answers5

32

you can try

if($(".ui-dialog").is(":visible")){
//dialog is open
}
Rafay
  • 30,950
  • 5
  • 68
  • 101
  • Something must be really odd with the styles on this page then. In firebug console while a dialog is open: $('.ui-dialog').is("visible") == false – lamont Feb 03 '12 at 15:08
  • 1
    @lamont - note the colon in front of `:visible` - it's a psuedo-selector. – Alnitak Feb 03 '12 at 15:08
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

ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
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*/
};
Touhid Alam
  • 343
  • 1
  • 5
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"
thenetimp
  • 9,487
  • 5
  • 29
  • 42
  • 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. – lamont Feb 03 '12 at 14:58
  • >>> $(".ui-dialog-content").css('display') "block" >>> $(".ui-dialog").css('display') "none" regardless of dialog state, in firefox at least. – lamont Feb 03 '12 at 15:02
  • 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! – thenetimp Feb 03 '12 at 15:11
-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.