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

16 Replies, 1521 Views

Yo Alex,
I feel your pain lol. Detecting a click from iframe for specific div can be tricky, but since it’s same-domain, you’re in luck. Have you tried using `contentWindow`? You can access the iframe’s DOM directly and attach an event listener to the div.

Something like this:
```javascript
const iframe = document.getElementById('yourIframe');
const iframeDoc = iframe.contentWindow.document;

iframeDoc.getElementById('specificDiv').addEventListener('click', () => {
console.log('Click detected!');
});
```
Let me know if this works for ya!

Messages In This Thread



Users browsing this thread: 1 Guest(s)