Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Trouble with dynamic iframe height
Old 05-23-2011, 05:47 PM Trouble with dynamic iframe height
Super Talker

Posts: 113
Trades: 0
I have a page on one of my sites that needs to show another of my sites in it, kind of like how about.com does it... Anyway, I tried following these instructions to dynamically change an iframe's height, but couldn't get it to work: http://www.mattcutts.com/blog/iframe...llbar-example/

Here is the code:

Code:
<html>
<head> <title>Parent frame</title> 
<script type="text/javascript">
// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame(f) {
f.style.height = f.contentWindow.document.body.scrollHeight + "px";
}
</script>

</head>

<body onload="resizeFrame(document.getElementById('childframe'))" bgcolor="#cccccc">



<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>

<p>
<iframe frameborder=0 border=0 src="http://www.google.com" name="childframe" id="childframe" width="100%">
</iframe>
</p>

</body>
</html>
Any idea why it's not working?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-23-2011, 06:57 PM Re: Trouble with dynamic iframe height
Super Talker

Posts: 113
Trades: 0
I don't really know anything about javascript, but I've been trying to figure out the problem and changed the code to this:

Code:
<html>
<head> 

<title>Parent frame</title> 

<script type="text/javascript">
// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame(f) {
alert('alert1');
f.style.height = f.contentWindow.document.body.scrollHeight + "px";
alert('alert2');
}
</script>

</head>

<body onload="resizeFrame(document.getElementById('childframe'))" bgcolor="#cccccc">

<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>

<p>
<iframe frameborder=0 border=0 src="http://www.google.com" name="childframe" id="childframe" width="100%">
</iframe>
</p>

</body>
</html>
As you can see, I added two alert boxes in the function. The first one pops up, but the second one does not. Does this mean that this line is causing a problem?:
Code:
f.style.height = f.contentWindow.document.body.scrollHeight + "px";
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 05-24-2011, 05:59 AM Re: Trouble with dynamic iframe height
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Yes, that's what is means.
I'm no javascript expert myself, but I'm *guessing* that different browsers has different support (perhaps has another name for the same thing or different spelling) for contentWindow or scrollHeight. So try to isolate the error by continuing your debugging.
Try to simplify that line, for example:

f.style.height = "200px";

If that works, the error lies in the right hand side of the equality sign.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 05-24-2011 at 06:00 AM.. Reason: typo
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Trouble with dynamic iframe height
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37916 seconds with 12 queries