Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

cross-iframe-and-window

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cross-iframe-and-window

a cross-origin message framework cross iframe and window(such as brower tab), with window.postMessage.

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

cross-iframe-and-window

a cross-origin message framework cross iframe and window(such as brower tab), with window.postMessage.

usage

import Cross from "cross-iframe-and-window"

const cross = new Cross({
  key: "child",
  isBase: true,
  parentOrigin: "*",
  timeout: 3000
});

cross
  .connect({
    key: "base",
    id: "child1"
  })
  .catch(() => {
    // 错误处理
    // 1. 超时
    // a. 对方无响应
    // b. origin 不匹配
    // 2. target 不存在或不合理
    // 3. connect 时注册重复
  });

cross.dispatch("sayHello", { nihao: 123 }, "child2").catch();

cross.disconnect("child2").catch(() => {
  // 1. target 不存在
  // 2. 超时
});

已知 bug

页面初始化的某个过程中,代码中 window.parent !== window,但是获取的 window.parentwindow。:( 但是实际上并不会触发回调以至于引起其他的问题。

Keywords

cross-origin message

FAQs

Package last updated on 26 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts