I was in this same situation and I found that using window.postMessage was a much better way to communicate between the frames: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
If you want to use the method you mentioned, every page that loads within the frame will need to manually set document.domain on load. The parent page will also need to set it. It is just a built-in javascript property of the document object.