Skip to content

beipiaoyu2011/crossStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crossStore 跨域存储

API

  • setProxyUrl(url)

    首先要设置要跨域读取数据的那个 url(首先要做的事情)

  • setItem(key, val)

    存。val可以是 Boolean、Number、String、Object

  • getItem(key, callback)

    取。以获取到的val作为实参调用callback,val存的时候是什么类型的值,获取到的就是什么类型的值

  • removeItem(key)

    删。

  • clear()

    全删。

  • change(callback)

    监听window.onstorage事件,setItem/removeItem/clear操作会触发storage事件,以{key, oldValue, newValue}作为实参调用callback。

    removeItem时,newValuenull;当clear时,key, oldValue, newValue均为null

examples:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>test</title>
<script src="https://huainanhai.github.io/crossStore/crossStore.js"></script>
</head>

<body>
TEST
<script>

    crossStorage.setProxyUrl('https://huainanhai.github.io/crossStore');

    crossStorage.getItem('theme', (e) => {
        console.log('theme', e);
    });

    crossStorage.change(function (e) {
        console.log(e.oldValue, e.newValue);
    });

</script>
</body>

</html>

About

user postMessage to solve CORS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published