I have upgraded the scripts to provide a getReplaceContext function that discovers the first enclosing element of class 'replaceContext'.

There is a problem related to identity of the node objects. If the IFrame is created lazily - on first use - then the node object to be replaced seems to lose validity.

Click on this to Introduce the same document but nested.

But click here to replace at the same level.

Try it and see what I mean.

This may seem like a crazy example, but it successfully demonstrates the general replacement technique and that it is structurally scalable.