4

I have an iFrame that is firing an event that I want the parent page to pick up. Essentially the inverse of this question. I can pick up the event inside the iFrame, so I know it's firing, but nothing happens in the parent.

I'm using YUI 3 so any answers based around this get a double-thumbs up, but all help is gratefully received.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rob Waring
  • 41
  • 3
  • Desperately seeking: an answer to this exact question. Did you make any headway? I found this: http://stackoverflow.com/questions/4601325/trigger-events-in-iframes-parent-window – danjah Feb 05 '11 at 04:43

1 Answers1

4

Apparently events don't propagate across frames. Here's how I'm working around it:

In the parent frame define this global function:

var fireGlobalEvent = function (e, param) {
  YUI().use('event-custom', function (Y) {
    var publisher = new Y.EventTarget();
    publisher.publish(e, {
      broadcast:  2,   // global notification
      emitFacade: true // emit a facade so we get the event target
    }).fire(param);
  });
};

Then just call this in the child to trigger the event in the parent.

window.parent.fireGlobalEvent('my_custom_global_event', 'an_extra_param');

Then the event is caught by parent modules with:

    Y.Global.on('my_custom_global_event', function (e, param) {
       // do something
    });
mjhm
  • 16,497
  • 10
  • 44
  • 55