Creating IFrame in a web page is easy and it is also easy to have one way communication with it. WebPage can send a message to IFrame using PostMessage, but IFrame cannot send the message back to parent window. It is not allowed.
There are scenario’s where you may need to get the message back from IFrame. In this post, i will be talking about how you can have a two way communication with IFrame.
As we know, IFrame cannot send the message back to the root web, then we are left only with one option to go out to a service and let that service send the message back to the root web. To have a good performance, we need to use web sockets for this communication. As you can see in the picture, the web page send the messages to IFrame using PostMessage, and when IFrame need to send any message back, it calls our SignalR server, which in turn calls the client method on parent web page.