homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Resize picture to fit in iframe
iframe resizing for pictures

10+ Year Member

Msg#: 10701 posted 9:39 am on Jul 27, 2005 (gmt 0)

I have a page and I want to have an iframe centered at the top and below it alot of little images, when I click on the image i want the image to resize to fit the iframe (obviously the image being bigger than the iframe)
Can anyone help
I dont know anything about php or the likes thank you


travelin cat

WebmasterWorld Administrator travelin_cat us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 10701 posted 6:13 pm on Jul 27, 2005 (gmt 0)

Assuming the larger graphic is 200x500, on the page with your iframe put this:

<iframe src="test.html" height="200" width="500"></iframe>

on test.html put this:

<a href="2.gif"><img src="1.gif" border="0"></a>

where 1.gif is the smaller graphic and 2.gif is the 200x500 graphic

When the viewer clicks on 1.gif, 2.gif will pop up filling the iframe beccause the iframe and it are the exact same size....

hope this helps.


10+ Year Member

Msg#: 10701 posted 2:17 pm on Jul 28, 2005 (gmt 0)

A very efficient way to get the results you're asking for, is to use a bit of server-side scripting. I'll put here a sample in ASP, but this is also doable on php and almost any server-side scripting technology.
Replace the $x, $y, $filename and things like those with the params you need.
The host file (the file where the iframe is):
<iframe name="the_frame" height="$y" width="$x"></iframe>
<a href="show_img.asp?fname=$file1.jpg" target="the_frame">
<img src="$file1.jpg" height="$y1" width="$x1" alt="click to enlarge" /> </a>
<iframe name="the_frame" height="$y" width="$x"></iframe>
<a href="show_img.asp?fname=$fileN.jpg" target="the_frame">
<img src="$fileN.jpg" height="$yN" width="$xN" alt="click to enlarge" /> </a>

The framed file "show_img.asp":
Dim strFile, strResponse
strFile = Request("fname")
strResponse = "<html><head></head><body>" & vbCrLf
strResponse = strResponse & "<img src=" & Chr(34) & strFile & Chr(34) & _
" height=" & Chr(34) & "$y" & Chr(34) & " width=" & Chr(34) & _
"$x" & Chr(34) & "/>"
strResponse = strResponse & "</body></html>"

The only difficult part is to keep html params "quoted" without these quotes being parsed by the ASP as opening/closing of strings. The call Chr(34) returns a 1-length string with the 34th character in ASCII, which is '"'. Beyond the weird thing of the quotes, I think there is no difficulty on implementing that; even so, if you have any doubt or question, I'll be glad to help you either via reply (generic questions) or sticky mail (if specifics are needed).

Hoping be useful,

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved