0

I have an Iframe with a content loaded from different domain:

<div class="iframe">
   <script language="javascript" type="text/javascript">
      var queryString = unescape(document.location.search.split('?id=').join(''));
      document.write("<iframe id=\"frame\" onload=\"resize()\" src=\"http://differentdomain.com/" + queryString + "\" scrolling=\"no\" width=\"850\" height=\"450\" frameborder=0></iframe>");
   </script>
</div>

The content of an Iframe can be of different height.

I have a method resize() executing when iframe loads as follows:

function resize() {
    var iFrameID = document.getElementById("frame");
    if (iFrameID) {
        iFrameID.height = "";
        iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
    }
}

When running the page I have an access denied error, I'm assuming because of cross-domain issues.

How can I fix that, so my frame's heights will be changed dynamically based on its content?

Thank's

eugene.it
  • 427
  • 2
  • 13
  • 31
  • If you [can control the page](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy), if you can't, there's nothing you can do due to the [Same-origin policy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript). – Teemu May 22 '14 at 14:30

1 Answers1

1

You can't. Except if you also control the other domain, then you can disable the protection.

FLX
  • 2,492
  • 4
  • 22
  • 49