Fire a jquery event in an iframe, run a callback in parent window -


i can fire event in scope of parent window iframe , listen, can't fire event iframe in scope of iframe , listen in parent windows.. example, in parent window, have iframe , jquery code listen events fired in it's body

<iframe id="myframe" src="/vf-install.php" width="500" height="500"></iframe> jquery('#myframe').contents().find("body").on('foo',function(){     alert('foo'); }); 

in iframe fire event:

<script type="text/javascript">jquery("body").trigger("foo");</script> 

i not event triggered. side note can trigger event in parent window iframe this:

parent.jquery("body").trigger("foo"); 

that unacceptable me though. reasoning vf-install.php being included via iframe installer program. writing regression test qunit includes installer in iframe, clicks install button, , when installer done (an event fired) test make assertion. therefore time it's included via iframe while under test. actual users call page directly , don't want firing events on parent window not there.

also side note tried attaching event listener iframe's body when load() called in case "live query" related issue (events aren't binded after ajax alters page):

jquery('#myframe').load(function(){     // attach event listener above }); 

could write generic handler pushing events?

function triggerevent(eventname) { if(undertest == true) { parent.jquery("body").trigger(eventname); } else {     jquery("body").trigger(eventname); } 

then can call triggerevent method in code, , have tests set 'undertest' variable true, or instead of having global var, inspect see if test harness present?

this solution doesn't feel overly pretty, might job.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -