When a window is opened using showModalDialog, return values can be sent to the opener window using 'window.returnValues'.
If the Torbutton state is toggled while the modal window is opened and then closed, the Javascript in the opener is executed in the previous state.