Adding event handler to an iframe using JQuery

contentWindow is the iframe's window object. You want the iframe's document instead:

$(document.getElementById('iframe_id').contentWindow.document).keydown(function() {
    // my func
});

Note that I am not sure how jQuery reacts to elements from other windows/frames.


Just something to keep in mind: this will never work, as far as I understand, if the iframe content is cross-domain. You'll end up with permissions errors: Permission denied for http://... to get property HTMLDocument.nodeType from http://.... Browsers limit parent child dom permissions to same domain.