![]() |
Can Perl do this window popup?
I've been told this can be done, I just don't know Perl well enough.
I have a large number of thumbnail images which when clicked on, I would like the enlarged image to show in a popup window. I have a template window I would like to use for all of the popups but I don't know how to insert the enlarged image into it. For example: The thumbnail image on the page is called 1234.jpg and its enlargement is named exactly the same only is located in directory: popup/1234.jpg. Is there a way to have the script automatically look for that image in that directory and call it into the popup template? I've been at this for almost two weeks now and I'm not getting very far. I can use JavaScript to open the window, but still need a way to specify which window and which image. Any insight to bring me sanity would be greatly appreciated -F- |
You don't strictly speaking need anything but JS for this one. This is off the top of my head and I'm no JS expert, so I may not be 100% right on all the details, but you can do something like this:
:
function popupImage(urlOfImage) {Where I've put "your template ..." you have the first part of your template, leading up to the src=\" part of the IMG tag where you want the image, of course; after the image URL, you put the rest of your template. When you call close(), you're calling win.document.close(), which makes the on-the-fly page appear. The with (object) { ... } syntax just saves me some typing. You could call win.document.open(), win.document.write() and win.document.close() if you prefer. You'd call this from your thumbnail by putting an <A> tag around it with an onClick attribute but href set to "". I believe this should work. The onClick can just call the above function passing in the appropriate URL for the larger image. Hope this helps! |
mackenga
Thanks for your reply! I've been tinkering with the code you supplied and haven't quite got it. I'm just a little confused about where to put the template information. I have a file with stylesheets and images that I was hoping to reference. You mentioned: Quote:
:
<body bgcolor="#FFFFFF" marginheight="0" topmargin="0" rightmargin="0" leftmargin="0" marginwidth="0" bottommargin="0">I am getting there, just need to figure this out to see if the rest of the script is working. Thanks in advance! -F- |
200% easier with javascript.
|
I posted some example code for this recently.
:
function enlarge (wURL, sp)EDIT: As a matter of fact, you can see this in action by clicking the "Digital Paintings" link in my signature. |
DaWei's code is definitely superior to mine, but does insist on loading the image directly into the new browser window, which doesn't let you add any page decorations around it. Some combination of my little example and DaWei's is the best answer I think - opening the window without a toolbar and menubar and so on is much cleaner than leaving all that standard browser clutter lying around on the screen.
Anyway, sorry it took me so long to get back to you. Where my code says "your template ..." you put all the HTML code leading up to the part where you put in the URL of the actual image to open the enlargement of; so right up to the src=" part of the IMG tag that refers to the image. After the URL, you put all of the rest of the code. This could get really messy but remember you can quote strings with single quotes in JS so you don't have to backslash escape every one of the double quotes in your HTML code, and you can join strings with + and put newlines anywhere outside strings you want, so you can actually lay out the code quite nicely: :
write("<HTML>\n" +The spaces at the starts of the strings and newlines at the ends are just so that the generated code keeps the nice layout - fairly pointless you might argue since nobody is ever likely to see it! What can I say? I'm a neat-freak. Hope this helps. |
McKenga's point is well taken. Once you have the handle to the window you can pop anything in there you like. I sometimes make "dialog boxes" in this fashion, thus precluding additional connections to the server.
|
Quote:
What I typically do is use a script to parse/display the HTML AND image, instead of linking directly to the image, or using JavaScript to output the HTML. All you really need to do is pass the image name and/or location to script, e.g. "/cgi-bin/printimage.cgi?image=images/mypic.jpg" Then, in the script, just get the "image" parameter value, and print out your entire template. Example of printimage.cgi: :
use CGI;As you can see, it doesn't take much code to do this. Adding error checking (to see if the image exists and print an error page, for example,) takes a little more, but not much. |
Thank you everyone for your replies! I've been very busy and haven't gotten a chance to reply sooner. You all have given me some great ideas and things to try! I have been working on something that I have very close to functioning now, however, I'm just having trouble inserting the main image. I figure that if I can't get what I have to work, I'll try another method.
I feel like I am soooo close with this! If you want to take a quick look at it and see where I might be going wrong, that would be great! The images are just test images for now, and they are in a folder called popup. Just view the source to see the code. The page with the thumbnails is located here and the popup page is here . Also, there seems to be an issue with Firefox where you can click on any part of the page and it will open the popup. This only happens x number of times where x is the number of thumbnails. After that it is fine. Thanks in advance! Let me know if there is any other information I can provide. -F- |
Why are you making it so difficult/complicated? I suggest you read your thread again.
|
| All times are GMT -5. The time now is 5:20 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC