iFrame Height Width

liunx

Guest
Is there a way to determine the height and width of the contents in an iFrame...?<!--content-->You can simlpy put the height and width attributes in the iframe tag like this.<br />
<iframe src=http://www.webdeveloper.com/forum/archive/index.php/"test.htm" height="500" width="500"></iframe><!--content-->Thank you...<br />
<br />
However, what I am trying to do is determine the height and width of the 'contents' of the iFrame so I can dynamically resize the height and width of the iFrame from the parent...<br />
<br />
I have put together a javascript function that will do exactly that:<br />
<br />
<script language="JavaScript"><br />
<br />
function iFrameHeight() {<br />
if(document.getElementById && !(document.all)) {<br />
h = document.getElementById('custFrame').contentDocument.body.scrollHeight;<br />
document.getElementById('custFrame').style.height = h;<br />
}<br />
else if(document.all) {<br />
h = document.frames('custFrame').document.body.scrollHeight;<br />
document.all.custFrame.style.height = h;<br />
}<br />
}<br />
</script> <br />
<br />
<br />
...<!--content-->Good work around, but what happens when a non-JavaScript user accesses your site??<!--content-->The only thing I could think of doing in that instance is to have a predertimed 'width' and 'height' that would work on normal instances...<br />
<br />
My iFrame also has 'scrolling=auto' so if it is not resized... they will still be able to scroll through the content...<br />
<br />
<br />
...<!--content-->True. But then again you have to realize that IFRAME is still relativly new, and that some browsers and any IE before v.5.5 will not render them. I'm not criticizing (sp?) your work, just offering input. :)<!--content-->Is a good thought...<br />
<br />
I will put a link to a popup window that will dispaly the same content...<br />
<br />
<iframe src=http://www.webdeveloper.com/forum/archive/index.php/"page.php" name="custFrame" align="left" style="height:175px;width:175px;" marginheight=0 marginwidth=0 border=0 scrolling=auto frameborder=0>LINK FOR POPUP WINDOW</iframe> <br />
<br />
Thank you... I would have had to learn the hard way... <br />
<br />
<br />
...<!--content-->Originally posted by Traffic <br />
Is a good thought...<br />
<br />
I will put a link to a popup window that will dispaly the same content...<br />
<br />
<iframe src=http://www.webdeveloper.com/forum/archive/index.php/"page.php" name="custFrame" align="left" style="height:175px;width:175px;" marginheight=0 marginwidth=0 border=0 scrolling=auto frameborder=0>LINK FOR POPUP WINDOW</iframe> <br />
<br />
Thank you... I would have had to learn the hard way... <br />
<br />
<br />
... <br />
<br />
YIKES!! That's even worse! lol. The pop-up would be triggered by JavaScript! So your backup plan for using an in-accessible technology is using another one??:p <br />
<br />
Even if the user supports JS, they might have a pop-up blocker. Going a bit further with it, most people hate pop-ups, and it may very well keep them from coming back to the site :(<!--content-->Just put a standard hyperlink to the iframe content between the iframe tags.<!--content-->I think:<br />
<br />
<br />
<script language="JavaScript"><br />
function iFrameHeight() {<br />
h=top.frames['custFrame'].document.body.scrollHeight;<br />
if(document.getElementById){<br />
document.getElementById('custFrame').style.height = h;<br />
}<br />
else if(document.all) {<br />
document.all['custFrame'].style.height = h;<br />
}<br />
}<br />
</script><br />
<br />
<br />
should be enough<!--content-->please forgive my asking but how do I involve that script into my iframe? :confused:<br />
<br />
regards<!--content-->You would put it in your <head></head> tags.<!--content-->aehm, thats not what I meant, I know that java scripts belong between the head tags but what i meant how I start the function (hope that describe it better)<br />
<br />
mfg<!--content-->I'm no JS expert but you may try onload in the body tag.<!--content-->I think my problem is that I don't want to open websites in the iframe but pictures (I know not a good idea) anyway I tried now to open the function with onclick and onload. Do I have to change the function somehow (for example put in the name of my frame somewhere?) or should I leave it just like it is? :confused: <br />
<br />
*beeingnearlyattheendofmypatiencewiththisiframe*<br />
<br />
mfg<!--content-->I honestly dont know all that much about JS but you may try naming your Iframe custFrame<!--content-->
 
Back
Top