Hi Pierre,
Looking at the iframe element, I don't think there's a lot you can do
if you want to use postmessage or pmrpc:
- you are right, you cannot read **any** attribute of the <iframe> element.
- i don't see a "name" attribute set in the iframe element, so you
cant use the window.parent.frames["destination_iframe_name"] to get a
reference. the "id" attribute is irrelevant, and even if it were
relevant - it's generated randomly so that's a dead end.
Here are some possibilities (which you probably wont like):
- contact the portal owner and ask them to implement some form of
inter-widget communication that doesn't require explicit
identification (e.g. like the pubsub API iGoogle had before -
http://code.google.com/apis/gadgets/docs/pubsub.html).
- implement a browser extension that helps you, e.g. a browser
extension that reads all the iframe elements in the portal page and
sends the list to the sending widget and assigns "name" attributes to
each. the sending widget then has everything it needs to figure out
which iframe element it needs to send to.
- wait for me to implement the pinging approach in pmrpc so you don't
have to do it manually. this is actually the base of my next feature
in pmrpc that allows discovery of registered methods - pmrpc would
ping each iframe it can reach and in return it would get a list of all
methods registered on those iframes. then you'd be able to call the
method you want without knowing in advance which iframe implements it.
but, as I said, this would be implemented in pmrpc using the pinging
approach, it would just be hidden from developers using pmrpc (like
yourself). i'm not sure when i'll be finished with this feature,
though.
Also, maybe you can use some other type of mechanism to communicate
(other than postmessage):
- use a server-mediated inter-widget communication mechanism. Here's
how that would work: you'd implement a service somewhere on the Web
(e.g. on appengine), and both of your widgets would know it's URL. the
sending widget would send something to the URL (e.g. using POST), and
the receiving widget would poll the URL (e.g. using GET) to see if the
sender sent something. in other words, your widgets would communicate
using a commonly known server
- perhaps you could use cookies or webstorage
(
http://dev.w3.org/html5/webstorage/) as a shared memory model, if all
the widgets are loaded from the same domain. here's how that would
work. since all the widgets are loaded from the same domain you can
access the same cookie/webstorage data from both widgets. thus, you
could write a message to a cookie/webstorage from the sending window,
and then read the data from the receiving window (e.g. by polling). I
didn't give this approach much thought, so I may have missed
something.
All in all - there's a lot of solutions, it just depends what your
project limitations are. The pinging approach is rather nice if you
ignore a few extra lines of code.
Hope this helps,
Ivan