title: cross-domain iframe resize
body: <p><strong>How do I resize an iframe from another domain?</strong></p>
  <p>Past few days I have been trying to integrate an iframe into a site. This is a short term solution while the other side develops and API(could take months...)
  And because this is as short term solution we done want to use easyXDM- I have access to the other domain but its difficult enough asking them to add p3p header as it is.....</p>
  <p><strong>3 iframes</strong></p>
  <p>The closest solution I found was the 3 iframes- but it goes mental of chrome and safari so I cannot use that.</p>
  <p>open in chrome</p>
  <p><a href="http://css-tricks.com/examples/iFrameResize/crossdomain.php#frameId=frame-one&amp;height=1179" rel="nofollow noreferrer">http://css-tricks.com/examples/iFrameResize/crossdomain.php#frameId=frame-one&amp;height=1179</a></p>
  <p><strong>Measure the scrollbars</strong></p>
  <p>I found a another post on how to use the scrollheight to try and resize the form.. in theory it works well but I could not apply it properly using the iframes scroll height..</p>
  <pre><code>document.body.scrollHeight
  </code></pre>
  <p>That obvoisly uses the bodies height (cannot access these properties 100% is based on the clients display canvaz and not the x-domains document height)</p>
  <p>I tried using jQuery to get the iframes height</p>
  <pre><code>$('#frameId').Height()
  
  $('#frameId').clientHeight
  
  $('#frameId').scrollHeight
  </code></pre>
  <p>return values different in chrome and ie - or just don't make sense at all.
  The problem is that everything inside the frame is denied- even the scrollbar...</p>
  <p><strong>Computed Styles</strong></p>
  <p>But if I inspect and element in chrome of the iframe it badly shows me the documents dimensions inside the iframe (using jQuery x-domain to get iframe.heigh - access denied)
  There is nothing in the computed CSS <img src="https://i.stack.imgur.com/wox5C.jpg" alt="" /></p>
  <p>Now how does chrome calculate that? (edit- browser re-renders the page using its build in rendering engine to calculate all these settings - but are not attached anywhere to prevent cross-domain fraud.. so..)</p>
  <p><strong>HTML4</strong></p>
  <p>I read specification of HTML4.x and it says there that there should be read-only values exposed via document.element but it's access denied via jQuery</p>
  <p><strong>Proxy Frame</strong></p>
  <p>I went down the route of proxying the site back and calculating which is OK.. until a user logs in through the iframe and the proxy gets a login page instead of the actual content. Also to some calling the page twice is not acceptable</p>
  <p><a href="http://www.codeproject.com/KB/aspnet/asproxy.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/aspnet/asproxy.aspx</a></p>
  <p><a href="http://www.johnchapman.name/aspnet-proxy-page-cross-domain-requests-from-ajax-and-javascript/" rel="nofollow noreferrer">http://www.johnchapman.name/aspnet-proxy-page-cross-domain-requests-from-ajax-and-javascript/</a></p>
  <p><strong>Re-Render the page</strong></p>
  <p>I did not go this far but there are jscript engines out there that will look at the source and re-render the page based on the source file. but it would require hacking those jscripts.. and that's not an ideal situation for commercial entities...
  and some invoke pure Java applets or server side rendering</p>
  <p><a href="http://en.wikipedia.org/wiki/Server-side_JavaScript" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Server-side_JavaScript</a></p>
  <p><a href="http://htmlunit.sourceforge.net/" rel="nofollow noreferrer">http://htmlunit.sourceforge.net/</a> &lt;-java not jscript</p>
  <p><a href="http://maxq.tigris.org/" rel="nofollow noreferrer">http://maxq.tigris.org/</a></p>
  <hr />
  <p>All this can do done with HTML5 sockets. But easyXDM is  great fallback for non HTML5 complaint pages.</p>
  <p><strong>Solution 1</strong> Very Great Solution!</p>
  <p>Using easyXDM</p>
  <p>On your server you set up a page in the form of</p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script src=&quot;scripts/easyXDM.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
  
      var transport = new easyXDM.Socket(/** The configuration */{
      remote: &quot;http://www.OTHERDOMAIN.example/resize_intermediate.html?url=testpages/resized_iframe_1.html&quot;,
  
      //ID of the element to attach the inline frame to
      container: &quot;embedded&quot;,
      onMessage: function (message, origin) {
          var settings = message.split(&quot;,&quot;);
          //Use jquery on a masterpage.
          //$('iframe').height(settings[0]);
          //$('iframe').width(settings[1]);
  
          //The normal solution without jquery if not using any complex pages (default)
          this.container.getElementsByTagName(&quot;iframe&quot;)[0].style.height = settings[0];
          this.container.getElementsByTagName(&quot;iframe&quot;)[0].style.width = settings[1];
      }
  });
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id=&quot;embedded&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  <p>and on the callers domain they just need to add the intermediate_frame HTML and <code>easyXDM.js</code>  in the same place. Like a parent folder - then you can access relative directories or a contained folder just for you.</p>