codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  How can I use javascript to load a image in different size when I click onto it in my thumbnail?  Archive Import (Etienne) at 16:29 on Saturday, May 31, 2003
 

How can I use javascript to load a image in different size when I click onto it in my thumbnail?

  Re: How can I use javascript to load a image in different size when I click onto it in my thumbnail?  Troy Wolf at 16:25 on Wednesday, July 16, 2003
 

I have a simple ASP script that creates a popup window automatically sized to exactly hold the image--unless the image is larger than the screen, in which case, it sizes to the full screensize. It works good enough! You call this popup using javascript that fires when the user clicks a thumbnail. Here are the 2 parts.

First, the ASP page. Copy between the lines and paste into a new document. Save as imgPop.asp.
---------------------------------------
<%
title=Request("title")
img=Request("img")
%>

<HTML>
<HEAD>
<TITLE><%=title%></TITLE>
</HEAD>
<style>
body {
margin:0;
background-color:#000000;
}
</style>
<script language=JavaScript1.2>
function winResize() {
scrHeight = screen.availHeight - 40;
scrWidth = screen.availWidth - 40 ;
imgWidth = document.getElementById(`img01`).width;
imgHeight = document.getElementById(`img01`).height;

if (imgWidth > scrWidth) { imgWidth = scrWidth }
if (imgHeight > scrHeight) { imgHeight = scrHeight }
winWidth=imgWidth+31;
winHeight=imgHeight+42;
resizeTo(winWidth,winHeight);

window.focus();
}
</script>
<BODY onload=winResize()>
<table cellspacing=0 cellpadding=0 border=0 height="100%" width="100%">
<tr>
<td align=center valign=middle>
<img id=img01 src="<%=img%>" border=0>
</td>
</tr>
</table>
</BODY>
</HTML>
---------------------------------------

Second, the javascript function to call the asp page popup.
---------------------------------------
function ImgPop(img) {
url = `imgPop.asp?img=` + img + `&title=` + img;
WinPop(`Photo`,url,640,480,`yes`);
}
---------------------------------------

Place the above function in your page or in a javascript include. Then when you want to show an image from a thumb do something like this:
<img src="/forum/myPhotoThumb.jpg" onclick="imgPop(`myPhoto.jpg`)">

Let me know if you have any problems with the code.
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: How can I use javascript to load a image in different size when I click onto it in my thumbnail?  Troy Wolf at 10:43 on Tuesday, August 05, 2003
 

I guess nobody reads or uses my answers, because the code I posted was missing something. I showed this line:

WinPop(`Photo`,url,640,480,`yes`);

But I didn`t provide the code for the WinPop() function. I`ll provide that code, but the simplest thing would be to replace the above line with these lines:

var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
winPhoto = window.open(url,"Photo","menubar=0,toolbar=0,resizable=yes,scrollbars=yes,width=640,height=480,top="+winTop+",left="+winLeft);

The code above is taken from my WinPop() function. winLeft and winTop serve to center the popup window in the user`s screen. Here is the WinPop() function that I use to pop most windows. It accepts arguments to control the look of the window. It`s not pretty, but is working code that I`ve used for a long time now.

function WinPop(winName, winSrc, winWidth, winHeight, scroll, menubar, toolbar) {
if (!scroll) { scroll = "no" }
var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
wname=window.open(winSrc, winName, "menubar="+menubar+",toolbar="+toolbar+
",resizable=yes,scrollbars="+scroll+",width="+winWidth+
",height="+winHeight+",top="+winTop+",left="+winLeft);
}


Troy Wolf: site expert
SnippetEdit Website Editor


  Re: How can I use javascript to load a image in different size when I click onto it in my thumbnail?  Elain at 02:34 on Wednesday, February 23, 2011
 

Why don't you search the question in google or some books? I think you must find the answer, good luck!
_________________________________________
My favorate tool,
logo maker|flash banner make|javascript menu








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: spaces between menus. possible?
•  Re: c# .net Exception of type System.StackOverflowException was thrown.
•  Re: Plz its urgent:validation code
•  Re: need help with main()
•  Re: The Dim appExcel As Excel.Application doesn`t work ????
•  Re: onclick thumbnail images in gridview or datalist
•  Re: good tutorial for creating global.asa?
•  Re: automatically updating
•  Re: dereferenceing a string to a constant name


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2011