https://github.com/krasimir/lsbridge
Using local storage as a communication channel
https://github.com/krasimir/lsbridge
Last synced: 6 months ago
JSON representation
Using local storage as a communication channel
- Host: GitHub
- URL: https://github.com/krasimir/lsbridge
- Owner: krasimir
- License: mit
- Created: 2015-05-05T07:06:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T20:50:31.000Z (about 8 years ago)
- Last Synced: 2025-03-25T16:56:08.266Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 472
- Watchers: 13
- Forks: 51
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](http://krasimirtsonev.com/blog/article/Using-Local-Storage-as-a-communication-channel).
## Usage
Add **lsbridge.min.js** to your page:
```html
```
There is a global object `lsbridge` available.
Send messages:
```js
lsbridge.send('my-namespace', { message: 'Hello world!' });
```Listen for messages:
```js
lsbridge.subscribe('my-namespace', function(data) {
console.log(data); // prints: { message: 'Hello world!'}
});
```Find out if `localStorage` is available:
```js
console.log(lsbridge.isLSAvailable); // prints "true" or "false"
```Cancel listeners for specific namespace:
```js
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.
