How to Detect a Click from an Iframe for a Specific Div? Need Help!

16 Replies, 1509 Views

Hey!
Detecting a click from iframe for specific div is definitely doable, but it can be a bit of a headache. One thing I’d suggest is using `window.frames` to access the iframe’s content. Here’s a quick snippet:

```javascript
const iframe = window.frames['yourIframeName'];
iframe.document.getElementById('specificDiv').addEventListener('click', () => {
alert('Div clicked!');
});
```
Make sure the iframe is fully loaded before running this, though. Otherwise, it’ll throw errors.

Messages In This Thread



Users browsing this thread: 1 Guest(s)