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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:30:55+00:00 2026-06-14T09:30:55+00:00

I have an iframe that loads in a page from my website and I

  • 0

I have an iframe that loads in a page from my website and I need to set it’s positioning to the center of the page dynamically based on the height of the iframe’s content, and I have had no issues with the code that I am using except that the height of the iframe’s content will never return a value lower than what it is if the content get’s smaller (if that makes sense).

The js recognizes when the content height grows, but not when it shrinks.

E.g. if I have a page that is 400px high, and then some content dynamically changes to 420px, my code will recognize that it is 420px high, but then if it changes to 350px, for instance, my code will still see it as being 420px high. How do I fix this?

Code:

function place()
{
    var w = $(window).width();
    w-=1000;
    w/=2;
    if(w<12)
    w = 12;
    $("#div").css("left",""+w+"px");
    $("#closeDiv").css("left",""+(w-12)+"px");

    var h = $(window).height();
    var ifh = document.getElementById("inner").contentWindow.document.body.scrollHeight;
    document.title = ifh;
    h -= ifh;
    h /= 2;
    if(h < 20)
    h = 20;
    $("#div").css("top",""+h+"px");
    $("#div").css("height",""+ifh+"px");
    $("#closeDiv").css("top",""+(h-12)+"px");
}

The document title continues to show the 420px, even when I know that the content is less than that. The same problem occurs for .offsetHeight.

Thanks for your help!

SOLUTION UPDATE

Okay, so I used the code in the answer I marked as solving the problem, as I did use it and it deserves credit for helping me solve this problem, but the actual problem that was involved here was that I had the height of the iframe set to be 100% of the container box; as soon as I set it to 99%, that fixed the problem. Not sure why…but hey!

Thanks for all of your help!

  • 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-14T09:30:57+00:00Added an answer on June 14, 2026 at 9:30 am

    Try something like:

    var iHeight;
    if ($("iframe").length > 0) iHeight = $($("iframe")[0].contentDocument || $("iframe")[0].contentWindow.document).height();
    

    Although good old fashioned ele call should work:

    var iHeight;
    if ($("iframe").length > 0) iHeight = $("iframe").height();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that loads an external HTML page into an iFrame. There
I have a portal application that loads external content (widgets) via an iframe. Users
I am currently developing a website and i need that the pages loads dynamically
I have an iframe that loads a page that I would like to disable
I have an iframe that loads a page that I would like to disable
I have a web page that loads in an IFRAME, that runs correctly in
I have a page P1 loading from site S1 which contains an iframe. That
I have a page which dynamically loads pages into an iframe. I found scripts
I have a script that dynamically loads iframes inside a webpage. You can see
I have a iframe that i want to open pdf's into from a list

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.