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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.