Here's the scenario, I have events happening from within an iframe and up until now everything is working well. I just ran into the problem where I want to dispatch an event from the iframe to the parent.
I'm using this to trigger the event from the iframe:
$('body', window.parent.document).trigger('eventName');
//and I've also tried
$(window.parent.document).find('body').trigger('eventName');
And then in the parent page I've listening for the event like this:
$('body').bind('eventName', myFunction)
I know the script gets to the trigger because I stuck a console.log
before and after the trigger. The iframe is on the same domain so there is no problem there.
I can call a function on the parent page directly like this: window.parent.functionName
but I was wondering if this is possible with using using an event based solution.
Solved
@cwolves answer is working great:
parent.$('body').trigger( 'eventName' );