views:

51

answers:

1

Hello - I am trying to send an event to iframes which have been opened by the application based on few events which should be prior registered by iframes.

I cannot figure out how. I use jquery but I don't expect the iframes to be nice citizens to implement listeners in jQuery. Though I can mandate it - I am still looking for normal javascript notifications.

Scenario

  • iframe A registers for entry event
  • iframe B registers for entry event

The parent gets notified by server and it sends events to both these iframes.

Thanks.

A: 

You could create a method on the parent that lets child pages register a listener.

something like

window.registerListener(callback) 

that way it's up to the iframes to tell the parent window that it's listening.

then use

window.parent.registerListener(function() {   
 // do stuff 
});

It'll only work if the iframes are on the same domain obviously.

Gareth
I don't understand why it would work only for iframes in same domain. It has no same domain policy.