How to make a XUI dialog close itself, when its "parent" document is closed?

The XUI wizard Keith Berard shows how Last Updated: 2006-08-08

Place this in your XUI code, as a child of the "window" element:

 <![CDATA [ var xuiwin = Application.event.target; // This is a DocumentUnload event listener function handleEvent(e) { if (xuiwin.parent.isSameComponent(e.relatedWindow)) { // e.target is the document e.target.removeEventListener("DocumentUnload", this, false); e.stopPropagation; xuiwin.close ; }  }   var o = { handleEvent: handleEvent }; var listener = Packages.org.w3c.dom.events.EventListener(o); var actdoc = Application.activeDocument; actdoc.addEventListener("DocumentUnload", listener, false);]]>