cors-window
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-alpha.8 • Public • Published

cors-window

Cross-origin window/iframe communication

Example

Host

const host = new DialogHost("http://localhost:7702")
host.onMessage = (data) => {
    console.log("child sent msg", data)
}
host.onChildAttach = () => {
    console.log("host has attached to existing window")
}
host.onChildOpen = () => {
    console.log("child opened a new window")
}
host.onChildClose = () => {
    console.log("child window closed")
}
setInterval(() => {
  host.post({ type: "ok", data: "data from host" })
}, 1500)

Dialog

const dialog = new DialogWindow();
dialog.onMessage = (data) => {
    console.log("parent sent message", data)
}
dialog.onParentOpen = () => {
    console.log("parent opend this window")
}
dialog.onParentAttach = () => {
    console.log("parent refreshed the window")
}
dialog.onParentClose = () => {
    console.log("parent closed the window")
}
setInterval(() => {
  dialog.post({ type: "ok", data: "data from dialog" })
}, 1500)

Examples

For full examples go to example directory

Readme

Keywords

Package Sidebar

Install

npm i cors-window

Weekly Downloads

18

Version

0.0.0-alpha.8

License

MIT

Unpacked Size

11.2 kB

Total Files

6

Last publish

Collaborators

  • farukon