I've used something like this as well when having a generic popup to do things.
Basically, you have a function on your window that you would pass to the popup, and the popup would call that function before closing to either pass data back, or provide a confirmation etc...