1

I am creating an iframe dynamically:

  function iFrame(parentElement)
  {
    var iframe = document.createElement("iframe");
    if (parentElement == null)
    {
      parentElement = document.body;
    }
    parentElement.appendChild(iframe);
    iframe.doc = null;
    if (iframe.contentDocument)
    {
      iframe.doc = iframe.contentDocument;          // Opera, Firefox
    }
    else if(iframe.contentWindow)
    {
      iframe.doc = iframe.contentWindow.document;   // Internet Explorer
    }
    else if(iframe.document)
    {
      iframe.doc = iframe.document;
    }
    if(iframe.doc == null)
    {
      throw "Application failed to dynamically create an iframe content";   
    }
    iframe.doc.open();
    iframe.doc.close();
    return iframe;
  }

...with document.onload:

  function onPageLoad()
  {
    var iframeDiv = document.getElementById("iframeDiv");
    var iframe = new iFrame(iframeDiv);
  }

How can I stretch this iframe to its parent div and turn off scrolling with JavaScript?

Daedalus
  • 7,586
  • 5
  • 36
  • 61
Ωmega
  • 42,614
  • 34
  • 134
  • 203

1 Answers1

3

You can turn off scrolling in the iframe by setting:

iframe.style.overflow = "hidden"

If the parent div has a defined height and width, then you can set the iframe to have 100% height and width:

iframe.style.width = iframe.style.height = "100%";

More info in this previous SO question/answer.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979