How would you implement postMessage?

I would like to use postMessage in my application to communicate with IFrames. This would normally require access to the Window object, which I don’t see implemented anywhere in Elm. Neither have I found a package which implements a wrapper around postMessage.

Judging by the documentation, I could implement this myself with a port. Is this correct or am I missing a simpler way?

ports is probably the way to go!

the other strategy I can think of would be wrapping your iframe thingy in a webcomponent and monitoring its attributes - then if something changed you could also trigger the message in a more declarative way. this is useful if your message is related to keeping some value synced between elm and your iframe.

either way - you will need to do it in JS land. ports is the global approach, webcomponents is the local approach (if that makes any sense).

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.