javascript - Difference between custom event and postMessage -
in order send message document (let's iframe
), can use both postmessage
, 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, difference between using postmessage
, customevent
?
it's difference between leaving neighbour message asking them turn down tv, , breaking apartment , turning down tv yourself.
you can't dispatch event frame not allowed access same origin policy or access-control-allow-origin, since of messages might mess how page works. messages intended communication between different pages - if don't want listen message, don't have to.
another difference messages must serialisable, events not have be.
Comments
Post a Comment