lsbridge

2019-08-20

Using the local storage as a communication channel

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.jsto your page:

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

There is a global object lsbridgeavailable.

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 localStorageis available:

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

Cancel listeners for specific namespace:

lsbridge.unsubscribe('my-namespace');

Compilation

  • Run npm installto get UglifyJS installed.
  • Run npm run-script compileto produce build/jsbridge.min.js

Example

Try it yourself by opening example/index.htmlin a browser.

lsbridge

Repository

https://github.com/krasimir/lsbridge.git


上一篇:jager
下一篇:gulp-protect
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部