Note that both parent and child need to include the jQuery postMessage javascript, and for communication to be enabled in browsers that don't support window.postMessage, the child page must know the exact parent URL (in this example, that is done by passing the parent location into the Iframe using a hash param in the Iframe src attribute).

The parent window code

  // Keep track of the iframe height.
  var if_height,
    // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
    // passed via query string or hard coded into the child page, it depends on your needs).
    src = '' + encodeURIComponent( document.location.href ),
    // Append the Iframe into the DOM.
    iframe = $( '<iframe " src="' + src + '" width="700" height="1000" scrolling="no" frameborder="0"><\/iframe>' )
      .appendTo( '#iframe' );
  // Setup a callback to handle the dispatched MessageEvent event. In cases where
  // window.postMessage is supported, the passed event will have .data, .origin and
  // .source properties. Otherwise, this will only have the .data property.
    // Get the height from the passsed data.
    var h = Number( /.*if_height=(\d+)(?:&|$)/, '$1' ) );
    if ( !isNaN( h ) && h > 0 && h !== if_height ) {
      // Height has changed, update the iframe.
      iframe.height( if_height = h );
  // An optional origin URL (Ignored where window.postMessage is unsupported).
  }, '' );
  // And for good measure, let's send a toggle_content message to the child.
  $( '<a href="#">Show / hide Iframe content<\/a>' )
    .appendTo( '#nav' )
      $.postMessage( 'toggle_content', src, iframe.get(0).contentWindow );
      return false;