First create a form, call it what you will. I typically call it 'Goaway'.
In my world the form is blank save for the following line entered in the HTML Body Attribute of the form:
In my forms which popup, I put the following lines behind a button or hotspot depending on the design.
When the action is triggered the document in the window gets saved and then within the same window the 'goaway' form is loaded. When that form loads it automatically closes the window.
That's it, data saved, window closed... process as usual.