1.0.4 • Published 5 years ago

commlinks v1.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Commlinks

Easy communication between window instances in JavaScript. You can also communicate between iframes and browser tabs too.

Online Demo

Installation

Step 1
npm i --save commlinks

If you do not want to add the package to your package.json file, do not use the --save flag.

Step 2

Include the commlinks JavaScript file in your project:

<script src="./node_modules/commlinks/dist/commlinks.min.js"></script>

Usage

Creating a Commlink instance

A global Commlinks object is available, you can register your Commlink instances in it.

Create a Commlink instance:

Commlinks.myWindow = new Commlink(window);

or if you prefer using a local variable:

let myCommlink = new Commlink(window);

The Commlink function always requires an instance of Window interface as a parameter.

Send message

Send message:

Commlinks.myWindow = new Commlink(window);

Commlinks.myWindow.send('someMessage')

Send message with data:

Commlinks.myWindow = new Commlink(window);

Commlinks.myWindow.send('someMessage', {test: 'Hello.'})

Send message with data and target:

Commlinks.myWindow = new Commlink(window);

Commlinks.myWindow.send('someMessage', {test: 'Hello.'}, 'https://example.org')

More information about the target origin: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Listen for messages

You can of course listen for messages, and run a callback.

Commlinks.on('someMessage', function (data, event) {
    // Do something
});

You can find examples in the examples folder.

If you have an idea or you want to request a feature, feel free to open an issue.

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago