proxy your iframe storage to parent, to fix some local storage issues in iOS Safari. link
scan to visit the demo
----------------------------------------
| domainA storage |
| ^ |
| | postmessage |
| ------------------------------- |
| | domainB | | |
| | V | |
| | a fake storage | |
| | | |
-----------------------------------------
npm i iframe-storage
<script src="https://cdn.jsdelivr.net/npm/iframe-storage@0.0.6/dist/ifrStorage.js"></script>
<script src="https://cdn.jsdelivr.net/npm/iframe-storage@0.0.6/dist/ifrStorageCli.js"></script>
top page
import "iframe-storage/src/ifrStorage"
iframe:
import {init} from "iframe-storage/src/ifrStorageCli"
init({scope:"demo"}).ready(function (){
localstorage.test=1
})
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) |