0.0.7 • Published 5 years ago
iframe-storage v0.0.7
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-storageor insert directly
top page, make sure insert it before your iframe. any where is ok
<script src="https://cdn.jsdelivr.net/npm/iframe-storage@0.0.6/dist/ifrStorage.js"></script>iframe
<script src="https://cdn.jsdelivr.net/npm/iframe-storage@0.0.6/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) |