Search code examples
javascripthtmliframepostmessage

javascript: listen for postMessage events from specific iframe


I have multiple iframes in a page. Now I have one message event listener for the page, which gets the messages from all of the iframes. I have a workaround to know from which iframe the message is coming.

I would like to make event listeners for each iframe separately. Is this possible?


Solution

  • No, it's not possible. Best you can do is to have a single handler that routes received messages to helper handlers based on the origin of the message sender.