Dynamic iFrame height, not working in ie without refresh.

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2007
Posts: 1
Reputation: Saion is an unknown quantity at this point 
Solved Threads: 0
Saion Saion is offline Offline
Newbie Poster

Dynamic iFrame height, not working in ie without refresh.

 
0
  #1
Mar 3rd, 2007
When i try to dynamically change the height of an iframe in ie through
a java-script to match its content (a html page containing a flash
movie), it doesn't resize the iframe at first, but when i reload the
same page into the iFrame it resizes as planned, how come? Any ideas?
This script works well in firefox, safari and netscape, but i cant get
it to work in ie(8, 7). And i get the same problems with every
resizing script i've tried.

This is the script i use:

<script type="text/javascript">
function adjustIFrameSize(iframe)
{
if ( iframe.contentDocument ) // firefox
{
iframe.height = iframe.contentDocument.height;
}
else // IE
{
iframe.style.height =
iframe.contentWindow.document.body.scrollHeight;
}

}


</script>
The iframes:

<iframe src="centriaMenu.php" name="menu" WIDTH="800" HEIGHT="200"
hspace="0" frameborder="0" marginheight="0" marginwidth="0"></IFRAME>

<iframe src="<?php print $_POST[fileName]?>" name="contents"
onload="adjustIFrameSize(this);" id="contents" height="200"
WIDTH="800" frameborder="0" marginheight="0" marginwidth="0" ></
IFRAME>

I have a flash menu in the first iframe, the buttons on the menu uses
getURL(siteToLoad, "contents") to load another html-page into the
iframe "contents".

Is it possible to make the iFrame refresh automatically though
javascript so that i just refreshes the iframe once? Everytime ive
tried that it just ends up in a never ending refresh-loop... How can i
make this work? Is there any better script for resizing (and
refreshing after resize) the iframe height so that it matches to its
content? Please, i've been stuck with this problem for some days
now...

// Max
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1
Reputation: swamp_safari is an unknown quantity at this point 
Solved Threads: 0
swamp_safari swamp_safari is offline Offline
Newbie Poster

Re: Dynamic iFrame height, not working in ie without refresh.

 
0
  #2
Mar 11th, 2007
I got exactly same problem today. IE sucks.

Here is my solution. This works for both IE and firefox.

html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <iframe id="myframe">
  2. <div id="content">
  3. </div>
  4. </iframe>

Javascript
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. height = document.getElementById("content").offsetHeight;
  2. document.getElementById("myframe").height = height;

Let me know if this works or not
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1
Reputation: h_aboulela is an unknown quantity at this point 
Solved Threads: 0
h_aboulela h_aboulela is offline Offline
Newbie Poster

Re: Dynamic iFrame height, not working in ie without refresh.

 
0
  #3
Oct 24th, 2007
Thanks a lot for both of you!!! I had the same problem but It's now working!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1
Reputation: CoolCow is an unknown quantity at this point 
Solved Threads: 0
CoolCow CoolCow is offline Offline
Newbie Poster

Re: Dynamic iFrame height, not working in ie without refresh.

 
0
  #4
Nov 14th, 2007
Originally Posted by swamp_safari View Post
I got exactly same problem today. IE sucks.

Here is my solution. This works for both IE and firefox.

html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <iframe id="myframe">
  2. <div id="content">
  3. </div>
  4. </iframe>

Javascript
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. height = document.getElementById("content").offsetHeight;
  2. document.getElementById("myframe").height = height;

Let me know if this works or not
Used your trick but it dousn't seem to work (using IE 7)
It looks like document.getElementById("content") returns NULL, so there's no reference to the object. probably because it's inside the iframe tags and that's only shown when the browser dousn't support frames.
Can you help me figure out how to get this to work?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Dynamic iFrame height, not working in ie without refresh.

 
0
  #5
Nov 15th, 2007
You opened the "height" can of worms, and now the only way to recan them is to get a bigger can.

First of all, whether the getElementById gets the correct value depends on how that value got there.

- The value is available if it got there through rendering of the original web page, or if it was set by the JavaScript program.

- A former value is returned if some dynamic content other than the JavaScript changed the attribute. An example is a div resizing itself to hold an object that was not loaded when the original page was rendered.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC