[Last Call] Learn how to a build a cloud-first strategyRegister Now


iFrame Auto Resize

Posted on 2008-11-18
Medium Priority
Last Modified: 2012-05-05
I have an iFrame that I'm trying to auto size like this:

<script  type="text/javascript">
    function setHeight() {
        parent.document.getElementById('test').height = document['body'].offsetHeight;

<iframe src="http://murfreesboro.granicus.com/ViewPublisher.php?view_id=2" frameborder=0 id="test" onload="setHeight()" scrolling=auto class=media    ></iframe>

(from the css) :

The page that the iframe is displaying comes from another location.  I do not have access to its code.  When the page loads, the javascript appears to work, but the page does not size to 100% of its contents.  The page inside of the iframe refreshes itself periodically, and when it does, the javascript incrementally adds extra height to the page. I would like to stop that incremental resizing if possible.   The page that I'm working on can be found here: 

I want the iframe to resize its height based on its contents. Is there a way to do that? Please let me know if I need to explain my problem any further.  Thanks for reading.
Question by:thedeal56
  • 4
  • 3
LVL 11

Expert Comment

ID: 22987853
Hi. Unfortunately you cannot resize your iframe based on the height of the document loading into it if it's from a different domain to the document requesting it.  This is a security issue.
A good alternative is to do a page scrape  
If u need info on this please let me know.

Author Comment

ID: 22987872
Yes, some more info on that would be helpful.  Thanks for your fast reply.
LVL 11

Accepted Solution

glumlun earned 2000 total points
ID: 22988366
hi, in VB a page scrape function would look like this:

    Public Function scrapeContent() As String

        Dim objWebClient As New WebClient()
        Dim strURL As String = "http://www.domain.com/page.htm"
        Dim aRequestedHTML() As Byte

        aRequestedHTML = objWebClient.DownloadData(strURL)
        Dim objUTF8 As New Text.UTF8Encoding()

        Return objUTF8.GetString(aRequestedHTML)

    End Function

by calling this you would get the whole content of a page in a string.

id recomend saving the string to a html file on your local server, and using it as the source of yout iframe

i have noticed that there are a lot of references in the iframe source to external files, these would need to be replaced with absolute urls using the replace function

without being able to access the code on the external domain you have no choice but to use scrollbars, try to predict the size of the page, or use scraping.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 22988404
That's cool.  I'll look into that.  Thanks agian.

Author Comment

ID: 22988494
I forgot to ask this:

This site is using the same company's external link, but they are displaying it through a traditional frame set.  If I were to use regular frames, could I achieve the same result?


From the site, click on departments -> channel 3 -> archives

That should put you to it.
LVL 11

Expert Comment

ID: 22988809
hi, as the src of the iframes is on the same domain your original scripts should work no problem.
ill monitor this post in case you have further questions


Author Comment

ID: 22989655
I'm not sure how to go about writing it to a html file.  Would it be too much trouble to ask for some help with that?

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question