0

I have made a function for automatically resizing of an iFrame. However, it works only when the content of iFrame is set to be from another web-site (could still be on the same server)... Guess there are some problems with calling of the function..

The iFrame and the resizing function is in the file Mainpage.aspx, the function is like this:

function setIframeHeight(iframe) {
    if (iframe) {
        var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
        if (iframeWin.document.body) {
            iframe.height = 17 + iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
        }
    }
};

It is called in the Page_load event:

ifrMain.Attributes.Add("onload", "setIframeHeight(document.getElementById('" + ifrMain.ClientID + "'));")

When the iFrame-content is in the same web as Mainpage.aspx, (http://aserver/web1/page1.aspx) it does not resize to fit the lenght of the content. When the content of the iFrame is from another web site (external or internal, i.e. http://aserver/web2.page1.aspx), it resizes just fine. Why?

I'm not deep into client-side scripting, may be I've missed something basic here??

Regards, John Martin

INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
  • Here you have answer [automatically-adjust-height](http://stackoverflow.com/questions/9975810/make-iframe-automatically-adjust-height-according-to-the-contents-without-using). – nisar Apr 05 '16 at 10:20
  • why you have mix up with the `parentWindow` ? – Aristos Apr 05 '16 at 10:22
  • also see this http://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-on-content-inside-jquery-javascript/9163087#9163087 – Aristos Apr 05 '16 at 10:22
  • Sorry, forgot to mention the iFrame is server-side based in Mainpage.aspx.. That's why the parentWindow has to be set. So these suggestions doesn't work, since they only work for clientside set iFrame. – John Martin Kvalsund Apr 05 '16 at 12:57

0 Answers0