In order to send a message to another document (let's say an iframe
), you can use both postMessage
and createEvent
functions. Assume this:
var event = document.createEvent('CustomEvent');
event.initCustomEvent("message", true, true, 'Hello world');
iframe.dispatchEvent(event);
My question is, if both approaches work, what is the difference between using postMessage
and customEvent
?