The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.
Send messages to iframe using iframeEl.contentWindow.postMessage
Recieve messages using window.addEventListener('message')
Send messages to parent window using window.parent.postMessage
Recieve messages using window.addEventListener('message')
@justlester you'll probably need to have the iframe at nesting level 1, propagate it to iframe at nesting level 2, and so on.
FWIW, I've created a library
protoframe
that adds a type wrapper around your iframe messaging protocol and has some helper functions to bind the listeners to the right window and establish "connection": https://github.com/mrvisser/protoframe