I have an iframe on a page, coming from a 3rd party (an ad). I'd like to fire a click event when that iframe is clicked in (to record some in-house stats). Something like:
$('#iframe_id').click(function() {
//run function that records clicks
});
..based on HTML of:
<iframe id="iframe_id" src="http://something.com"></iframe>
I can't seem to get any variation of this to work. Thoughts?
None of the suggested answers worked for me. I solved a similar case the following way:
The css (of course exact positioning should change according to the app requirements):
Of course now you can catch any event on the iframe-wrapper.
Solution that work for me :
You can solve it very easily, just wrap that iframe in wrapper, and track clicks on it.
Like this:
<div id="iframe_id_wrapper"> <iframe id="iframe_id" src="http://something.com"></iframe> </div>
And disable pointer events on iframe itself.
#iframe_id { pointer-events: none; }
After this changes your code will work like expected.
$('#iframe_id_wrapper').click(function() { //run function that records clicks });
You could simulate a focus/click event by having something like the following. (adapted from $(window).blur event affecting Iframe)