Skip to content

mindonline/post-messages-dispatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Post Message Dispatcher class

##Usage as master:

const site_url = "http://example.com/";
let iframe = document.querySelector('iframe');
iframe.src = site_url;
iframe.addEventListener('load', ()=>{
    let dispatcher = PostMessageDispatcher(iframe.contentWindow, site_url, "mychannel");
    dispatcher.listen( message =>{
        console.log("Message received as master: ", message);
    });
    dispatcher.send("myaction", {some_payload: 123})
})

##Usage as slave:

let dispatcher = PostMessageDispatcher(window.parent, "*", "mychannel");
dispatcher.listen( message =>{
    console.log("Message received as slave: ", message);
});
dispatcher.send("myaction2", {some_payload2: 321})

About

Send and receive messages with PostMessages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published