🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

ifapi

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifapi

iframe api

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
32
-11.11%
Maintainers
1
Weekly downloads
 
Created
Source

iframe api binding

说明

iframe 页面通过 postMessage 函数导出 api (函数),并支持在父页面调用 api,获取返回值。

使用方式

1. 安装

npm install ifapi --save

2. 使用

1. iframe 页面导出 api
const handlers = {
    greet: function(name: string) {
        alert(`hello, ${name}`);
    },
    sum: function(args: { a: number, b: number }) {
        const { a, b } = args;
        return a + b;
    }
}

exportAPI(handlers);
2. parent 页面调用 api
	// <iframe id="my-frame" src="http://www.test.com/frame.html"></iframe>
	excute("my-frame", "sum", { a: 1, b: 2 })
		.then((data) => console.log(data))
		.catch((error) => console.error(error));

Keywords

iframe

FAQs

Package last updated on 25 Jun 2023

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