How to "connect" a dialog to a document?

Clay Helberg tells how to use the "appdata" attribute on the "window" element Last Updated: 2006-10-24

=N.N. writes=

I've been asked to play the role of a XUI developer in an upcoming reality TV series. While researching for this role, I encountered two problems:

(Editor's Note by Liz Fraley -- #1 moved to separate topic: How to enable several users to use the same XUI file concurrently?)

(2) Keeping code linked to a specific instance of a dialog and document

Keeping code linked - When it comes to keeping events and code changes linked, I don't have code to illustrate. Basically, a user opens Document A and this spawns Dialog A. User decides that the information is similar to something else and opens Document B, spawning Dialog B.

Everything is fine until the user goes back to Dialog A and starts making changes, expecting those to happen on Document A.

Can anyone share any tricks in how they keep changes specific to Dialog A linked to Document A?

=Clay Helberg=

As for tying a XUI dialog to its correct document when multiple documents are open, the parent property is probably the canonical method for doing so. However, I find the methods for getting from a dialog to a view to a document and back again a bit tedious, so I do it a different way: when the dialog opens (usually in response to an event on the target document), I set the appdata attribute on the dialog document's element to the target document ID. That way I always know where to find it when I need to look it up, with a simple dlgdoc.documentElement.getAttribute("appdata").