iframe-click-away
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

npm version

iframe-click-away

◇ Most tooltip and popup tools has a "click away" feature, which allows users to close a tooltip, popup, or modal by clicking anywhere outside of it.

◇ When there's a iframe in page, "click away" won't work between regions in outer page and in inner iframe.

◇ This tool is used to let "click away" work in the above scenario, with less codes.

◇ Mechanism: when a click occurs on one side, a mimetic click will be triggered on the other side at (clientX, clientY), which defaults to (2,2).

usage

◆ Install this npm dependency.

◆ On the outer side:

import { Outer } from 'iframe-click-away';

// get iframe window
const iframeWindow = iframe.contentWindow;

// provide info about inner iframe and outer page, and outer optional mimetic click position.
const outer = new Outer(iframeWindow, window /*,clientX, clientY*/);

// init
outer.init();

// invoke deinit() when destroying process is needed
outer.deinit();

◆ On the inner side:

import { Inner } from 'iframe-click-away';

// get outer page's window
const outerWindow = window.parent;

// provide info about inner iframe and outer page, and inner optional mimetic click position.
const inner = new Inner(window, outerWindow /*,clientX, clientY*/);

// init
inner.init();

// invoke deinit() when destroying process is needed
inner.deinit();

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.11latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.11
1.0.04
1.0.0-beta0
1.0.0-alpha0

Package Sidebar

Install

npm i iframe-click-away

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

8.29 kB

Total Files

13

Last publish

Collaborators

  • yuancongzhou