🧪 在线测试

📥 存储数据

📤 查询数据

📋 通信日志


iframe 存储通信 — 对接文档 & Demo

📋 对接文档

通信方式

使用 window.parent.postMessage(data, '*') 向父页面发送消息,
通过 window.addEventListener('message', handler) 接收父页面回复。

1. 存储数据 Request

字段类型必填说明
typestring固定值 "set-storage"
keystring存储键名,见下方校验规则
valueany存储的值,支持 string / number / object / array 等

Response

字段类型说明
typestring"storage-set"
keystring请求的 key
successboolean是否存储成功
messagestring成功返回 "xxx stored successfully",失败返回具体错误原因

2. 查询数据 Request

字段类型必填说明
typestring固定值 "get-storage"
keystring查询的键名

Response

字段类型说明
typestring"storage-get"
keystring请求的 key
existsboolean是否存在该 key 的数据
valueany存在时返回存储的值,不存在时为 null
messagestring不存在时返回 "not found"

3. 校验规则 Constraints

规则限制违规时返回的 message
Key 字符 仅允许 A-Z a-z 0-9 _ . - invalid key: only letters, numbers, underscore, dot, hyphen allowed
Key 长度 最长 64 字符 key too long, max 64 chars
Key 必填 必须为 string 类型 invalid key: key is required and must be a string
单 Value 大小 最大 100KB value too large, max 100KB
总存储容量 所有 iframe 数据合计上限 2MB storage quota exceeded, max 2MB total for iframe data
Key 数量 最多 50 个 key too many keys, max 50 keys allowed
localStorage 异常 浏览器存储满等极端情况 storage failed, localStorage may be full

⚠ 所有 iframe 存储数据均以 iframe_ 为前缀写入 localStorage,与宿主项目数据隔离,不会相互影响。