Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:40:04+00:00 2026-05-15T13:40:04+00:00

I have some javascript inside an iframe that sends the height of the iframe

  • 0

I have some javascript inside an iframe that sends the height of the iframe body to the parent page using the three frame technique at Resizing an iframe based on content

The height of the iframes body always seems to come out at 900, the viewport height of the iframe. This is consistent across browsers.

The iframe:

<iframe id="printiq" src="http://myurl.com" height="900px" width="980px">Your browser does not support iframes.</iframe>

The script inside the iframe:

$(window).load(function() {
    var height = document.body.scrollHeight + 60;
    alert('Height: ' + height); //Always returns 900, the height of the iframe
    var whirlwind_url = 'http://whirlwind.ben.dev/iframe_helper';
    var iframe_html = '<iframe id="height_helper" src="'+whirlwind_url+'?height='+height+'"></iframe>';
    $('body').append(iframe_html);

});

The weird thing is when I inspect the DOM with firebug none of the height variables (scrollHeight, offsetHeight etc) are set to 900.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:40:04+00:00Added an answer on May 15, 2026 at 1:40 pm

    The problem was a div on the iframed page was expanding to the height of the viewport. I fixed it by changing the css.

    Here is the code I ended up with.

    Parent window.

    function resizeIframe(height) {
        height = parseInt(height) + 60;
        $('iframe#printiq').attr('height', height); 
    }
    

    The script for the iframed external site.

     $(window).load(function() {
        var height = $('#container').height() + $('#header').height();
        var whirlwind_url = 'http://whirlwind.ben.dev/iframe_helper';
        var iframe_html = '<iframe id="height_helper" src="'+whirlwind_url+'?height='+height+'"></iframe>';
        $('body').append(iframe_html);
    

    });

    The iframe helper, which gets embedded into the iframe. A grandchild of the browser window if you like.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <!--
        This page is on the same domain as the parent, so can
        communicate with it to order the iframe window resizing
        to fit the content
        -->
        <body onload="parentIframeResize()">
            <style type="text/css">
                body{
                    border:none;
                    display:none;
                }
            </style>
            <script>
                // Tell the parent iframe what height the iframe needs to be
                function parentIframeResize()
                {
                    var height = getParam('height');
                    // This works as our parent's parent is on our domain..
                    parent.parent.resizeIframe(height);
                }
    
                function getUrlVars()
                {
                    var vars = [], hash;
                    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                    for(var i = 0; i < hashes.length; i++)
                    {
                        hash = hashes[i].split('=');
                        vars.push(hash[0]);
                        vars[hash[0]] = hash[1];
                    }
                    return vars;
                }
    
                // Helper function, parse param from request string
                function getParam( name )
                {
    
                    var results = getUrlVars();
                    if( results == null )
                        return "";
                    else
                        return results['height'];
                }
            </script>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do this on most systems using popen (or… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer You're sorting at the wrong level. If you want to… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer To find them anywhere in the document, use xdoc.Descendants("ARTICLE") to… May 15, 2026 at 3:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.