Making an iframe just big enough, but no bigger

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    #1

    Making an iframe just big enough, but no bigger

    Hi,

    Does anyone know a cross-browser way of making an iframe just as big
    as the HTML content of its source, but no bigger, either width or
    height wise. Using 100% attributes for iframe width and height seem
    to make the iframe as big as its parent container. I would also
    prefer a solution where there is no scrolling.

    Thanks for any help, - Dave

  • Jukka K. Korpela

    #2
    Re: Making an iframe just big enough, but no bigger

    Scripsit laredotornado@z ipmail.com:
    Does anyone know a cross-browser way of making an iframe just as big
    as the HTML content of its source, but no bigger, either width or
    height wise.
    There is none. That would be against the principles of iframe rendering: the
    iframed document is presented autonomously, and the document that embeds it
    just offers a display area for it. Using client-side scripting, you might be
    able to detect the size requirements of the iframed document, though I doubt
    that, and it would surely not be cross-browser.
    Using 100% attributes for iframe width and height seem
    to make the iframe as big as its parent container.
    More or less so.
    I would also
    prefer a solution where there is no scrolling.
    This sounds like you would like to smoothly include a file in another.
    That's not really a job for iframe, and it's discussed in the FAQ.

    --
    Jukka K. Korpela ("Yucca")


    Comment

    • George L. Sexton

      #3
      Re: Making an iframe just big enough, but no bigger

      On Wed, 14 Mar 2007 13:30:19 -0700, laredotornado@z ipmail.com wrote:
      Hi,
      >
      Does anyone know a cross-browser way of making an iframe just as big
      as the HTML content of its source, but no bigger, either width or
      height wise. Using 100% attributes for iframe width and height seem
      to make the iframe as big as its parent container. I would also
      prefer a solution where there is no scrolling.
      >
      Thanks for any help, - Dave
      There are some scripts on http://www.DynamicDrive.com that will do this as
      long as both pages are in the same domain/host.

      Search their site for IFRAME

      Comment

      • scripts.contact@gmail.com

        #4
        Re: Making an iframe just big enough, but no bigger


        George L. Sexton wrote:
        On Wed, 14 Mar 2007 13:30:19 -0700, laredotornado@z ipmail.com wrote:
        >
        Hi,

        Does anyone know a cross-browser way of making an iframe just as big
        as the HTML content of its source, but no bigger, either width or
        height wise. Using 100% attributes for iframe width and height seem
        to make the iframe as big as its parent container. I would also
        prefer a solution where there is no scrolling.

        Thanks for any help, - Dave
        >
        There are some scripts on http://www.DynamicDrive.com that will do this as
        long as both pages are in the same domain/host.

        If both pages are from same domain then all you need to do is check
        scrollHeight/scrollWidth -

        IFrame.width=IF rame.document.b ody.scrollWidth
        IFrame.height=I Frame.document. body.scrollHeig ht

        E.G.-UNTESTED-

        <html>
        <head><title>So metr</title>
        <script type="text/javascript">

        function OpenFrame(){
        var Iframe=document .frames[0]
        Iframe.src="som ePage.html"
        Iframe.onload=
        function(){
        Iframe.width=If rame.document.b ody.scrollWidth
        Iframe.height=I frame.document. body.scrollHeig ht
        }
        }

        </script>
        <body style="text-align:center">
        <button onclick="OpenFr ame()">Text</button><br>
        <IFRAME src="about:blan k" width="50%" height="30%">yo ur browser
        doesn;t support frames(bad browser :-< )</iframe>
        </body>
        </html>

        Comment

        Working...