Closed Thread Icon

Topic awaiting preservation: Autosizing iFrame (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8898" title="Pages that link to Topic awaiting preservation: Autosizing iFrame (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Autosizing iFrame <span class="small">(Page 1 of 1)</span>\

 
Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-10-2003 20:12

Hello,

I am looking for an easy way to make an iFrame automatically expand to fit the height (and width, perhaps) of the content inside it. I have a simple script that does this if a page is on my site, but it fails if the page is not on my site, which is a problem. Do you know any way to do this?
Also, is there any way to get the current URL of an iFrame even if it's not on my site? Assuming that people have clicked on links inside it.

Thanks.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-13-2003 08:49

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-13-2003 22:10

Yes, that I knew. Isn't there a more natural way of making an iframe expand to the size of its content?

MajorFracas
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2003

posted posted 10-14-2003 20:54

This is definitely a security issue re: cross-site scripting and cannot be done in standard browsers. (I have spent a few hours trying much the same thing...)

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-15-2003 23:44

Grah! I fully understand that. I am not a total newbie to all this.
What I mean, is there no more natural way for this? Divs and table cells try to automatically resize to fit their content, can that be done with iframes?

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 10-23-2003 03:45

Hope lingers eternal... anyone have an idea, please?

Scott
Bipolar (III) Inmate

From: schillmania.com
Insane since: Jul 2002

posted posted 10-23-2003 03:59

I can't say I've seen any examples on it.. Percentages on the width/height for the iFrame are only be in relation to the parent "containing" element (likely the body of the main document in this case), of course. To auto-size, the only thing I can think of is to use a javascript method.

Have you tried a different method like using a DIV instead as a container, and writing content to it that way? Can your design work that way or be adjusted? I suspect iFrames just don't "automagically" size themselves to the dimensions of their content. That would be like a browser window doing the same thing in a sense, which the only solution that comes to mind for is Javascript. But the domain problem, as you mentioned.. argh.

enoctis
Obsessive-Compulsive (I) Inmate

From: Atlanta, GA - USA
Insane since: Dec 2003

posted posted 12-20-2003 18:41

I have managed to put together this code, which MANY of you were looking for. To the CODE!

In your page where the iframe will be contained, use the following code (add attributes more as needed):

<iframe id="dynamIframe">
---------------------------------------------
Now, in ANY page that is to be loaded into the iframe insert the following code (preferably between the <head> & </head> tags)

<script>
function resizeToContent(){
var x =0;
var y =this.document.body.scrollHeight;
while (x < y){
x+=1;
}
parent.document.getElementById("dynamIframe").style.height=x
}
</script>
---------------------------------------------
Finally, use the following as the body tag in the same pages as the javascript above:

<body onload="resizeToContent()">
---------------------------------------------
TADA! Hope this helped all of you guys out!


-os2

« BackwardsOnwards »

Show Forum Drop Down Menu