I have an iframe based widget that uses postMessage to communicate with a parent. This means that I am sending a message from an iframe to request the size itself. The json data is also currently interfering with messages sent by other widgets / scripts on the parent page.
So, I need a way to distinguish my own posts from others.
Now I just want to add the parameter { app: 'Poules.com', [...] } and check this parameter before processing the message.
But before I do this: are there any contracts for this already?
Sending Code:
parent.postMessage( JSON.stringify(data), page.widgetOrigin );
Final result:
poules.sdk.receiveMessage = function(event) { var data = JSON.parse( event.data ); switch ( data.message ) { case 'requestResize': poules.sdk.requestResize( data ); break; case 'loginSuccess': poules.sdk.triggerLoginEvent( data ); break; default: throw "poules.sdk: can't parse message: " + event.data; }; }
source share