Code Monkey home page Code Monkey logo

localstorage-share's Introduction

localStorage Share

浏览器本地存储共享 引入后可以调用一个本地公共存储空间,用于不同域的站点进行数据共享

NPM JavaScript Style Guide

Install

Using NPM

npm install localstorage-share
import lss from 'localstorage-share';

Using a CDN

If you don't want to use npm to manage client packages, localstorageShare also provides a UMD distribution in a dist folder which is hosted on a CDN or Download:

<script src="https://unpkg.com/localstorage-share/dist/index.js"></script>

localstorageShare will then be installed on window.localstorageShare. window.localstorageShare will contain the following properties:

localstorageShare.setItem(key,value)
localstorageShare.getItem(key)
//..

Usage

A站

// pageA.index.js
import lss from 'localstorage-share';

lss.setItem('origin','From PageA')

(async () => {
    const value = await lss.getItem('origin');
    console.log('A站拿到的值', value)
})();

B站

// pageB.index.js
import lss from 'localstorage-share';

(async () => {
    const value = await lss.getItem('origin');
    console.log('B站拿到的值', value)
})();

lss.setItem('origin','From PageB')

C站

<-!pageC.index.html->
<script src="https://unpkg.com/localstorage-share/dist/index.js"></script>

<script>

    (async () => {
        const value = await localstorageShare.getItem('origin');
        console.log('A站拿到的值', value)
    })();
    
    localstorageShare.setItem('origin','From PageC')
</script>

API

API Description Return
getItem (key:string) 获取值 {key:value}
setItem (key:string,value:string) 设置值 {key:value}
removeItem (key:string) 移除指定值 {key:value}
getItems () 获取当前存储中所有值 {LSS:items}
clear () 清空内存 {LSS:items}
init (serve:string) 内存服务器的部署路径 {LSS:items}

关于安全

localStorageShare 默认没有域名限制,如果处于安全性考虑可以在iframe中定义一个白名单,并把它重新部署。

License

MIT © browniu

localstorage-share's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.