iFrame Auto Resize

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.
Who is Participating?
glumlunConnect With a Mentor Commented:
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.

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.
thedeal56Author Commented:
Yes, some more info on that would be helpful.  Thanks for your fast reply.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

thedeal56Author Commented:
That's cool.  I'll look into that.  Thanks agian.
thedeal56Author Commented:
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.
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

thedeal56Author Commented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.