Adjusting iframe height's and width to source document?

Posted on 2006-04-21
Last Modified: 2011-09-20
For the past day and a half i've been researching on how to solve this problem... based on much googling it seems that there's no way around this due to  security issues. But I am a firm believer that there's always an answer to everything...

here's a snippet of the javascript in the HTML:

document.write('<iframe id="media" src="http://dogfighter.localhost/l?id=1" width=0 height=0 hspace=0 vspace=0 frameborder=0 marginheight=0 marginwidth=0 scrolling=no style="visibility: hidden" ></iframe>' );

I set the width and height initially to 0 to make it "invisible"

and then when the user clicks a certain link, the iframe pops up showing the varying content

so in my javascript that handles the onclick event of the link, i have something like:

var frameObj = document.getElementById("media");
innerDoc = frameObj.contentDocument.body.scrollHeight; //generates error

i get an erro as a result...

Error: uncaught exception: Permission denied to get property HTMLDocument.body

Does anyone have a resolution to this? thanks in advance.
Question by:lapchern
    LVL 9

    Accepted Solution

    There IS a security issue that prevents you from accessing the document object of a page not belongings to the domain on which your script is executed.
    You can not do anything to pass through this wall.
    But you can access to the window object (the iframe) containing the page.
    So you can resize it, but not in function of its content (as you can not compute the width/height of it).
    You could do it only if your main page were on se same domain.

    Author Comment

    argh for the first time in my programming life, i feel helpless. well if i get no workaround from anbody else in a few days, i'll hook u up with the points. thanks.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now