Having 2 "out of domain" pages in one aspx page with dynamic heights

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #31
    I have a working "Cookies" solution.

    The thing is you'll have to edit the pages that you are loading into the iframes.

    I only worked with 1 iframe but you'll have to modify the code so that a cookie is set by each page you're loading and that the code loading the iframe retrieves these cookies and sets the sizes accordingly.

    So, like I said I only worked with 1 iframe.
    I set a cookie called "heightCook ie" to the physical height of the window + the scroll height of the window (the height of the content) in the page I was loading in the iframe:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function setCookie()
    { 
      var value = document.body.offsetHeight + document.body.scrollHeight+ "px";
      var c_name = "heightCookie";
      document.cookie= c_name + "=" + value;
    }
    </script>
    <body onload="setCookie();">
     ......
    </body>
    </html>
    Then in the page that loads the HTML into the iframe I retrieve the heightCookie's value during the iframe's onload event and set the height of the iframe:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function getHeight()
    { var c_name = "heightCookie";
      if (document.cookie.length>0)
      {
       c_start=document.cookie.indexOf(c_name + "=");
       if (c_start!=-1)
       { 
         c_start=c_start + c_name.length+1 ;
         c_end=document.cookie.indexOf(";",c_start);
         if (c_end==-1) c_end=document.cookie.length
         return unescape(document.cookie.substring(c_start,c_end));
       } 
      }
     return "";
    }
    
    function autoResize(element)
    {  
        element.style.height = getHeight();
    }
    </script>
    </head>
    <body>
    <iframe onload="autoResize(this);" src="HideShowColumnsTest.html" id="testing"></iframe>
    </body>
    </html>
    It would probably be a good idea to load save cookies named according the the page name...and during the onload event pass the page name into the "autoResize " method...which passes it onto the getHeight method so that it retrieves the proper cookie for the iframe it's modifying.

    I haven't tested it across domains...I hope it works for you.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #32
      Unless you have control of both domains, you're going to have problems. JavaScript doesn't normally allow access to other domains. The probable easiest solution is to serve the pages from your own domain. How do you do that? Use server-side code to request the pages using a Http request.

      Comment

      • Manikrag
        New Member
        • Jun 2009
        • 62

        #33
        I tried your example on my local system Frinavale. It is close but still its not giving the accurate height. It is still returing 200px when I do not have anything in the child page.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #34
          What did you use to capture the size in the page that you're loading in the iframe?
          It seems that if you use the document.body.o ffsetHeight alone it will return you the iframe's height. You have to add this to the document.body.s crollHeight to determine how large the content actually is.

          -Frinny

          Comment

          Working...