https://github.com/springload/react-iframe-click
Detect clicks on iframe (but not within)
https://github.com/springload/react-iframe-click
Last synced: 6 months ago
JSON representation
Detect clicks on iframe (but not within)
- Host: GitHub
- URL: https://github.com/springload/react-iframe-click
- Owner: springload
- Created: 2019-09-03T02:11:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-27T23:38:49.000Z (about 4 years ago)
- Last Synced: 2024-12-02T09:41:20.728Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/react-iframe-click
- Size: 5.86 KB
- Stars: 14
- Watchers: 13
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Iframe click
Cross-domain ``s don't have click events, but they can be inferred with this library.
Just pass in an `onInferredClick` handler and you'll receive a callback when the iframe is clicked/tapped the first time.
# How?
We can check for a window blur event, and then see if focus has moved to the iframe from which we infer a click.
Because it's infering clicks by focus changes if the focus stays within the iframe it will only be able to infer clicks once.
This library is less than 1kb and has TypeScript bindings.
# Usage
```jsx
import Iframe from 'react-iframe-click';
// in a render...
alert('You clicked')}
>;
```
# Requirements
Peer dependency on React 16.8 or later.