javascript - jQuery: click event inside iframe -
i'm trying fire click event on click of element inside iframe, doesn't seem working. current set up:
jsfiddle: http://jsfiddle.net/q4aa3/
jquery:
$(document).ready(function () { $('#this-iframe').load(function () { $('#this-iframe').contents().find('img').live({ click: function () { alert('clicked img'); } }); }); });
clicking on image inside iframe isn't firing alert, i'm not sure why, or there better way achieve this? suggestions appreciated!
when have iframe on same domain, can use script catch clicks in iframe. don't use .live, depriciated of jquery 1.7.
var iframebody = $('body', $('#iframe')[0].contentwindow.document); $(iframebody).on('click', 'img', function(event) { dosomething(); });
you can manipulate body through iframebody variable.
Comments
Post a Comment