How to add click event to a iframe with JQuery

There’s no ‘onclick’ event for an iframe, but you can try to catch the click event of the document in the iframe:

document.getElementById("iframe_id").contentWindow.document.body.onclick = 
function() {
  alert("iframe clicked");
}

EDIT
Though this doesn’t solve your cross site problem, FYI jQuery has been updated to play well with iFrames:

$('#iframe_id').on('click', function(event) { });

Update 1/2015
The link to the iframe explanation has been removed as it’s no longer available.

Note
The code above will not work if the iframe is from different domain than the host page. You can still try to use hacks mentioned in comments.

Leave a Comment