Skip to content

Instantly share code, notes, and snippets.

@tylerbutler
Created November 4, 2016 18:13
Show Gist options
  • Save tylerbutler/d3af3c38b074855faa6f680b40442096 to your computer and use it in GitHub Desktop.
Save tylerbutler/d3af3c38b074855faa6f680b40442096 to your computer and use it in GitHub Desktop.
Simple PostMessage logger
function handlePostMessage(e) {
// The actual message is contained in the data property of the event.
var msg = JSON.parse(e.data);
// The message ID is now a property of the message object.
var msgId = msg.MessageId;
// The message parameters themselves are in the Values
// parameter on the message object.
var msgData = msg.Values;
console.log(msgId + '\n\n' + JSON.stringify(msgData));
if(msgId == "App_LoadingStatus"){
// Handle a specific message here if you want.
}
}
window.addEventListener('message', handlePostMessage, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment