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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -