jQuery trigger()
only calls callbacks that were added through .on()
its own instance. That way, the jQuery in your iframe will only initiate callbacks that were set using this instance, and not any settings through the jQuery instance of your main page.
dispatchEvent()
document.dispatchEvent(new Event('preview.compiled'));
window.onMessage/window.postMessage Broadcast Channel api
window.onMessage/window.postMessage,
window.addEventListener('message',function(message){
if(message.data.type=="preview.compiled"){
}
});
parent.postMessage({
type:'preview.compiled",
other:"other data to pass"
},"url of main window");
API onMessage/postMessage,
var bc = new BroadcastChannel('preview:compiled');
bc.onmessage = function(message){
console.log(message.data);
};
var bc = new BroadcastChannel('preview:compiled');
bc.postMessage('Some data');