Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-04-2012, 03:30 PM   PM User | #1
Sx, codeforums
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sx, codeforums is an unknown quantity at this point
Autoresize Iframe inside Show hide Javscript PLEASE HELP

Hi Iam new here. I got a login so i could ask all of you this question. I appoligies in advance for my bad english.
Can someone please tell me why the following code does not work. The iframe and the show hide option do work on there own but when combined the iframe show a tiny litte box.

If someone know i would be delighted!

<html>
<HEAD>
<link rel="stylesheet" type="text/css" Href="../exscript/hideunhide.css" />
.hidden { display: none; }
.unhidden { display: block; }


<link rel="stylesheet" type="text/css" Href="../exscript/Bomenbestand.css" />
IMG.ondergrond {position:fixed; left:-150; top:-150px; z-index:-1;}

.transbox {background-color:#ffffff; opacity:0.75; filter:alpha(opacity=90); /* For IE8 and earlier */}

table.center {margin-left:auto; margin-right:auto;}
table, th, td {border: 0px solid black;}
table, th, td {-moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 20px;}

table.transbox {SCROLLBAR-ARROW-COLOR: #A9A9A9; SCROLLBAR-BASE-COLOR: #FFFFFF;}
table.transbox {border-spacing: 0px; padding: 10px; }
td.padding {padding: 5px;}
td.transbox {padding: 15px;}

A:link {text-decoration: none; color: black;}
A:visited {text-decoration: none; color: black;}
A:active {text-decoration: none; color: black;}
A:hover {text-decoration: underline; color: red;}

div.bold {font-weight:bold;}



<script type="text/javascript" src="../exscript/hideunhide.js"></script>
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
item.className=(item.className=='hidden')?'unhidden':'hidden';
}
}


<script type="text/javascript" src="../exscript/autoiframeresize.js"></script>
function autoResize(id){
var newheight;
var newwidth;

if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}

document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}



</HEAD>

<body>

<TABLE BORDER="1" CLASS="transbox" WIDTH="100%">
<TR><TD>
<a href="javascript:unhide('learnHTML1');"> EIK (QUERCUS)</a>
<div id="learnHTML1" class="hidden"><iframe src="EIK/Eik.html" WIDTH="100%" id="iframe1" onLoad="autoResize('iframe1');"></iframe> </div>
</TD></TR>

<TR><TD>
<a href="javascript:unhide('learnHTML2');"> EIK (QUERCUS)</B></a>
<div id="learnHTML2" class="hidden"><iframe src="EIK/Eik.html"></iframe></div>
</TD></TR>
</TABLE>

<iframe src="EIK/Eik.html" WIDTH="100%" id="iframe2" onLoad="autoResize('iframe2');"></iframe>

</body>
</html>
Sx, codeforums is offline   Reply With Quote
Old 09-05-2012, 12:59 AM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 975
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Code:
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
You are appending 'px' to the height attribute, which it does not expect.
Try either of the following:

Using height/width attributes:
Code:
document.getElementById(id).height = newheight;
document.getElementById(id).width = newwidth;
Using CSS
Code:
document.getElementById(id).height = (newheight) + "px";
document.getElementById(id).width = (newwidth) + "px";
Also you can lose if(document.getElementById)
Logic Ali is offline   Reply With Quote
Old 09-05-2012, 08:57 AM   PM User | #3
Sx, codeforums
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sx, codeforums is an unknown quantity at this point
Logic Ali,

The script still does not work.
Thanks a ton for you're reply!
I have changed the .js and got rid of the "px". The outcome in my browser is the exact same as when before. When i combine the two scripts it only shows the iframe as i tiny little square.

Thanks for explaning the css bit.

function autoResize(id){
var newheight;
var newwidth;

{
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}

document.getElementById(id).height = newheight;
document.getElementById(id).width = newwidth;
}
Sx, codeforums is offline   Reply With Quote
Old 09-05-2012, 10:39 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 975
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Assuming your framed document has a strict doctype:

Code:
newheight=document.getElementById(id).contentWindow.document.documentElement.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document.documentElement.scrollWidth;
Logic Ali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Advertisement
Log in to turn off these ads.