iframe-storage
v0.0.7
Published
uses parent's storage
Downloads
14
Maintainers
Readme
iframe-storage
proxy your iframe storage to parent, to fix some local storage issues in iOS Safari. link
scan to visit the demo
How it work:
----------------------------------------
| domainA storage |
| ^ |
| | postmessage |
| ------------------------------- |
| | domainB | | |
| | V | |
| | a fake storage | |
| | | |
-----------------------------------------
install
npm i iframe-storage
or insert directly
top page, ~~make sure insert it before your iframe~~. any where is ok
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ifrStorage.js"></script>
iframe
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ifrStorageCli.js"></script>
usage
top page
import "iframe-storage/src/ifrStorage"
iframe:
import {init} from "iframe-storage/src/ifrStorageCli"
init({scope:"demo"}).ready(function (){
localstorage.test=1
})
ifrStorageCli config
| name | type | default | desc | | ---- | ---- | --- |---- | | target | window | window.top | use target's storage | | scope | string | | to isolate storage, empty means use parent's storage directly | | targetOrigin | string丨array | * | postmessage's targetOrigin | | localStorage | boolean | true | handle localStorage | | sessionStorage | boolean | true | handle sessionStorage | | when | function | null | execute if return true ,empty means always execute | | ready | function | null | same as init().ready(fn) |