Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Return A Value From A postMessage() call asynchronously?

I'm trying to get a value from local storage on a site loaded through an Iframe. I'm able to send a message to the site within the iframe through postMessage, but haven't figured out how to return data from the postMessage call. I've looked into promises, but haven't figured out how to get it working.

Anyone have an idea?

like image 209
Harry Manback Avatar asked Oct 30 '22 09:10

Harry Manback


1 Answers

I iframe window needs to listen for the "message" event, process the message, and then send a postMessage back to the window of the messenger.

You can read about the API here: window.postMessage().

David Walsh has also written a good tutorial on how to do this.

I hope this helps!

like image 118
Kyle Richardson Avatar answered Nov 15 '22 06:11

Kyle Richardson