Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect click event inside iframe

I'm writing a plugin for TinyMCE and have a problem with detecting click events inside an iframe.

From my search I've come up with this:

Loading iframe:

<iframe src='resource/file.php?mode=tinymce' id='filecontainer'></iframe> 

HTML inside iframe:

<input type=button id=choose_pics value='Choose'> 

jQuery:

//Detect click $("#filecontainer").contents().find("#choose_pic").click(function(){     //do something       });  

Other posts I've seen usually have a problem with different domains (this hasn't). But, still, the event isn't detected.

Can something like this be done?

like image 936
Philip G Avatar asked Nov 18 '12 10:11

Philip G


1 Answers

I solved it by doing like this:

$('#filecontainer').load(function(){          var iframe = $('#filecontainer').contents();          iframe.find("#choose_pics").click(function(){                alert("test");         }); }); 
like image 195
Philip G Avatar answered Sep 21 '22 23:09

Philip G