Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Adjusting iframe height's and width to source document?

Posted on 2006-04-21
Medium Priority
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

Accepted Solution

smaccari earned 1000 total points
ID: 16513151
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

ID: 16528056
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

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.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

571 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