Skip to content
Using local storage as a communication channel
JavaScript HTML
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build Adding unsubscribe method #5 Sep 24, 2016
example Initial commit May 5, 2015
src Adding unsubscribe method #5 Sep 24, 2016
.gitignore Filling the main field in the package.json #6 Aug 10, 2017
LICENSE Initial commit May 5, 2015
README.md Adding unsubscribe method #5 Sep 24, 2016
package.json Filling the main field in the package.json #6 Aug 10, 2017

README.md

The Local Storage Bridge

1K library for exchanging messages between tabs in a same browser. It uses the local storage as a communication channel.

The story behind the library is available here.

Usage

Add lsbridge.min.js to your page:

<script src="js/lsbridge.min.js"></script>

There is a global object lsbridge available.

Send messages:

lsbridge.send('my-namespace', { message: 'Hello world!' });

Listen for messages:

lsbridge.subscribe('my-namespace', function(data) {
  console.log(data); // prints: { message: 'Hello world!'}
});

Find out if localStorage is available:

console.log(lsbridge.isLSAvailable); // prints "true" or "false"

Cancel listeners for specific namespace:

lsbridge.unsubscribe('my-namespace');

Compilation

  • Run npm install to get UglifyJS installed.
  • Run npm run-script compile to produce build/jsbridge.min.js

Example

Try it yourself by opening example/index.html in a browser.

lsbridge

You can’t perform that action at this time.