The function initIframe will initialize the iframe:
Parameters:
- url: the iframe URL
- height: the height of the iframe
It will add the current document location to the iframe url for use in the iframe, and call $.receiveMessage for catching the iframe's sent messages.
Function handleIframeMsg will expect an obj with a property 'action' (you can implement this in any way you want), i only show you the resizing of the iframe here. This object is made through a deparam function (attached to this post), and does the opposite of jQuery's $.param function.
This must be implemented in the child (the iframe).
function sendToParent (obj){ var parent_url = decodeURIComponent( document.location.hash.replace( /^#/, '' ) ); $.postMessage(obj,parent_url,parent); }
and can be triggered like so:
sendToParent({action:"resize", params:{height:200, width:100}})
If you have any questions, feel free to ask.