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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -