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 8687157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:02:56+00:00 2026-06-12T23:02:56+00:00

Possible Duplicate: Resizing an iframe based on content I’m trying to load one of

  • 0

Possible Duplicate:
Resizing an iframe based on content

I’m trying to load one of my pages into an iframe. I’m never sure how big the page will be, the data on the page is loaded dynamically. I’d like the iframe to always fit the page, no matter how big or small it is. Here’s what I have:

function loadModal() {
    myframe = $('<iframe id="mymodal" src="MyPage.aspx" width="700"></iframe>');

    myframe.appendTo($('html'));

    var height = document.getElementById('modalPreview').contentWindow
                     .document.body.scrollHeight;

    $("#mymodal").attr("height", height);
}

I’ve been trying to get the height of the page after it’s loaded. The problem is that height comes back as 0. But if I do this:

    setTimeout(function () {
        $("#mymodal").attr("height", height);
    }, 2000);

the correct height is loaded. I assume it’s because the data needs a few seconds to load. But this looks funky if the page loads really fast, or it will still give me a height of 0 if it takes more than 2 seconds to load the page.

So is there a way to:

  1. Wait and set the height of the iframe once the data loads, or
  2. Set the height of the parent iframe from MyPage.aspx?
  • 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-06-12T23:02:57+00:00Added an answer on June 12, 2026 at 11:02 pm

    If you’re going to use option #2 you can access the parent window using the DOM and set the iframe height from the child.

    $(document).ready(function() {
        var iframeWin = parent.document.getElementById("yourIframeID");
        iframeWin.height = document.body.scrollHeight;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Resizing an iframe based on content What I am trying to do
Possible Duplicate: Realloc is not resizing array of pointers Can anyone tell me where
Possible Duplicate: Able to see a variable in print_r()'s output, but not sure how
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: Resizing an Image without losing any quality The code I always use
Possible Duplicate: Image resizing web service many web provider have support for php but
Possible Duplicate: How do I create a directory and parent directories in one Perl
Possible Duplicate: Image size got bigger when trying to reduce its size What I
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?

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.