I understand that it is not possible to tell what the user is doing inside an iframe
if it is cross domain. What I would like to do is track if the user clicked at all in the iframe
. I imagine a scenario where there is an invisible div
on top of the iframe
and the the div
will just then pass the click event to the iframe
.
Is something like this possible? If it is, then how would I go about it? The iframes
are ads, so I have no control over the tags that are used.
As found there : Detect Click into Iframe using JavaScript
=> We can use iframeTracker-jquery :
You can do this to bubble events to parent document:
Just extend the eventlist for more events.
The following code will show you if the user click/hover or move out of the iframe:-
You need to replace the src in the iframe with your own link. Hope this'll help. Regards, Mo.
This definitely works if the iframe is from the same domain as your parent site. I have not tested it for cross-domain sites.
Without jQuery you could try something like this, but again I have not tried this.
You can even filter your results:
Based in the answer of Paul Draper, I created a solution that work continuously when you have Iframes that open other tab in the browser. When you return the page continue to be active to detect the click over the framework, this is a very common situation:
The Code is simple, the blur event detect the lost of focus when the iframe is clicked, and test if the active element is the iframe (if you have several iframe you can know who was selected) this situation is frequently when you have publicity frames.
The second event trigger a focus method when you return to the page. it is used the visibility change event.
see http://jsfiddle.net/Lcy797h2/ for my long winded solution that doesn't work reliably in IE