2

all. I'm trying to create a widget that users can put on their site. I'm taking a page out of Facebook's book and let the users add using code like this crude example:

<script src="blah.js"></script> <my:widget id="whatever"></my:widget>

This then creates a div containing an iframe inside of the tag.

Now, here's the tricky part. If a user clicks a button inside of this frame, it needs to expand the widget. So, I need to tell the div wrapping around the iframe to change its width and height. All I need to do is send a single flag up so blah.js can read it and do its thing. I tried adding an onload handler to the iframe and change to a different page, but the parent frame cannot read the current iframe's location.

When observing Facebook's like button behavior for liking pages (eg: ), I noticed that they insert an expanded frame into the DOM exactly like I want to do so that a user can add a comment. I just don't know how one manages to communicate to the other.

Any ideas?

Martin Boynton
  • 115
  • 2
  • 9
  • This library supports HTML5 postMessage and legacy browsers with resize+hash https://github.com/ternarylabs/porthole (Ben Alman's jQuery Plugin hasn't been touched in 3 years) – jpillora Feb 27 '13 at 14:46
  • 1
    One possibility to communicate between cross domain frames is the HTML5 [postMessage](https://developer.mozilla.org/en/DOM/window.postMessage) API. There is also a [jQuery plugin](http://benalman.com/projects/jquery-postmessage-plugin/) which simplifies its usage and even better it falls back to url fragment manipulation in order to communicate for browsers that do not yet support this method. – Darin Dimitrov Sep 02 '11 at 21:41

0 Answers0