View Full Version : Popup Image Viewer

07-09-2002, 12:52 AM
I wrote this a long time ago and it seems to get posted in the forums quite a bit so I figured I post it here for easy reference:

<script language="Javascript" type="text/javascript">
function imageView(imgFile,imgTitle,imgWidth,imgHeight,winPosX,winPosY){
preview = window.open("","","resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+imgWidth+",height="+imgHeight+",left="+winPosX+",top="+winPosY+"");
preview.document.write('<html><head><title>'+imgTitle+' - Click to close - <\/title><\/head>'
+'<body onBlur="self.focus();" marginWidth="0" marginHeight="0" topmargin="0" leftmargin="0">'
+'<a href="java script:self.close()">'
+'<img border="0" alt="Image loading please wait...." src="'+imgFile+'" width="'+imgWidth+'" height="'+imgHeight+'">'

<!--// Parameter list as follows:
Image File
Title of Image
Width of Image
Height of Image
Window Position X coordinate
Window Position Y coordinate

Example of use:

<a href="javascript:imageView('images/australia08.jpg','Australian Limestone Desert',427,277,50,50)">
<img src="images/australia08thumb.jpg" width="84" height="55" border="0" alt="Click for larger image"></a>

If you want to use this download the attached text file instead of copying and pasting from the screen here. The forum keeps putting spaces in the coding when copying and pasting causing the script to have an error.

07-09-2002, 01:59 AM
I'm glad you put this here, as I've had to copy it from my pages numerous times for the forums.

One important note:
While you can take the <script> portion and put it in an external JS file for use/calling on multiple pages, N6 blanks...and subsequently won't complete the function. Therefore, for cross-browser usage, the <script> part needs to be put in the <head> of each and every page upon which you want to use it.

Thanks Spookster! :thumbsup:

07-22-2002, 04:11 PM
Spookster -

Your code is exactly what I was looking for, except there seems to be a problem when I use it. The script activates, but cannot find the image (checked image path of course, and made sure the image is THERE of course). Tried several things, but all I get is "URL not found on this server"

Sorry to be so dense, I'm just a Javascript newbie. Maybe there is something basic I screwed up (I cut and pasted the code, but maybe something got screwed along the way). Frustrating, and probably a simple problem. Any help would be appreciated!

07-24-2002, 06:15 PM
Spookster -

I found my error. Thanks for making me look twice!!:o

The SoupNazi @ http://www.ChefOnTheEdge.com

The Great One
07-24-2002, 09:06 PM
Nice code i had wrote something simalar and submited it here

It does the same thing as yours i think or very simalar.

Nice to see other people think pop up image thumbs are a good thing. hehe.


09-22-2002, 06:11 PM
Here is the attachment. Couldn't seem to put it in my original post