So far I\'ve only seen tutorials for postmessage where one window sends a single kind of message, and the other window interprets the message in only a single way.
What
One pretty easy way to trigger callbacks without passing any actual code would be:
Target
var callbacks = {
myCallback: function() { doSomething(); }
};
window.addEventListener('message', function (ev) {
// origin checking etc
callbacks[ev.data]();
}, false);
Source
target.postMessage('myCallback', 'http://www.example.com');