5

I am running a function that needs to close a Dojo dialog if it is loaded. How do I check if a dojo dialog is running? Do I use pure JavaScript and check by id if it is undefined?

if (dijit.byId("blah") !== undefined) { 
     destroyRecursive dijit;
}

Or do I use a property of the dialog object like:

isFocusable method
isLoaded property
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
shawn deutch
  • 427
  • 1
  • 6
  • 10
  • This is the end function: function bufferAddress(xCoord, yCoord) { if (dijit.byId("selectLocationDlg") !== undefined) { dijit.byId("selectLocationDlg").destroyRecursive(); } // some other code here } – shawn deutch Jul 21 '09 at 18:03

2 Answers2

4

Dialog provides two properties you might want to check: isLoaded and open. By digging the code you'll find the following descriptions:

  • open: True if Dialog is currently displayed on screen.
  • isLoaded: True if the ContentPane has data in it, either specified during initialization (via href or inline content), or set via attr('content', ...) / attr('href', ...) False if it doesn't have any content, or if ContentPane is still in the process of downloading href.

So, you could just:

var dialog = dijit.byId("blah");
if( dialog.open ) {
    dialog.destroy();
}
Maine
  • 1,878
  • 13
  • 10
  • 8yrs later, you should use `if (dialog && dialog.open)` or some other safe-check that `dialog` exists (`typeof(dialog) != 'undefined'`, `dialog != null`, etc). – Daevin Jul 06 '17 at 14:33
1

Do you want to hide it or destroy it?

If you just want to show/hide it you can do the following:

var dialog = dijit.byId('blah');
if (dialog) {
  if (dialog.open) {
    dialog.hide();
  }
  else {
     dialog.show();
  }
}

If you wanted to destory it to free up memory:

var dialog = dijit.byId('blah');
dialog.destory();

I think destroy is recursive since it calls its parent destroy method and one of its parents is dijit.layout.ContentPane.

seth
  • 36,759
  • 7
  • 60
  • 57