PDA

View Full Version : Resizing Iframe



Olen
Nov 28th, 2009, 12:21 AM
Hi folks! Very, very new to Javascript and I'm having a problem. What I'm trying to do is create a page that uses an iframe to show the fullsized image, while using thumbnails at the bottom. I need the iframe to resize depending on the size of the image since some are landscape and others are portrait oriented. I found a script online that did it for the height of the picture so I tried to modify it to do both the width and the height and haven't had much luck. Here's the code, and I apologize in advance for my noob coding.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Halloween 2009</title>
<script language="JavaScript">
<!--

function calcWidth()
{
//find the width of the internal page
var the_width=
document.getElementById('preview').contentWindow.
document.body.scrollWidth;

//change the width of the iframe
document.getElementById('preview').width=
the_width;
}

function calcHeight()
{
//find the height of the internal page
var the_height=
document.getElementById('preview').contentWindow.
document.body.scrollHeight;

//change the height of the iframe
document.getElementById('preview').height=
the_height;
}

//-->
</script>

<style type="text/css">
body {background: url(background/bg3.gif); text-align:center}
img {height: 5em; width:5em; display: inline; border: none}
</style>
</head>

<body>
<div style="height: 448px">
<iframe src="Halloween '09 021.jpg" name="preview" id="preview" onLoad="calcWidth();calcHeight();" marginheight="0" marginwidth="0" scrolling="no">
An iframe capable browser is required to view this web site.
</iframe>
</div>
<div id="thumbnails" style="padding-top: 1.5em; width: 40em; text-align: center">
<a href="Ariana.JPG" target="preview"><img src="Ariana.JPG" alt="" /></a>
<a href="Halloween '09 002.jpg" target="preview"><img src="Halloween '09 002.jpg" alt="" /></a>
<a href="Ayesha.jpg" target="preview"><img src="Ayesha.jpg" alt="" /></a>
ETC...
</div>

</body>
</html>