jhit
9/7/2016 - 9:57 AM

automatic Iframe resizing without Cross-Origin issues

automatic Iframe resizing without Cross-Origin issues

<iframe id="superiFrame" src="..." style="width: 100%; border: none;" scrolling="no" height="500"></iframe>

<script type="text/javascript">
  window.addEventListener('message', function(e) {
    var iframe = document.getElementById('superFrame');
    var eventName = e.data[0];
    var height = e.data[1];
    switch(eventName) {
      case 'setIframeHeight':
        iframe.height = height;
        break;
    }
  }, false);
</script>
<body onLoad="resizeParent();">
  
<script type="text/javascript">
  function resizeParent() {
    var height = document.getElementsByTagName("html")[0].scrollHeight;
    window.parent.postMessage(["setIframeHeight", height], "*");
  }
</script>

</body>