Forum Moderators: open
As I did not want to use Target Blank in all those links the result is that every time someone decides he wants to look at a certain picture the jpeg opens in the same window. If he wants to see more he clicks Back and selects a new link. The list page with its graphics was loaded again.
Most people are not interested in seeing all or most the pictures, but occasionally someone is. And some visitors have disabled their browser's cache function, so that poor page and its graphics are being loaded by the same person hundreds of times with a 200 response.
This is not a serious problem (so far), but is there some cleverer way? Log statistics are distorted. With Target Blank code added to every link more overall bandwidth would probably be used up than the present system does. I would not like to split the list.
Here's how:
In the HEAD section of your main document add some javascript:
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=435,height=550,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
Then, on your links, call the js function popup:
<a href="http://www.mydomain.com/ImageName.php" onClick="return popup(this, 'pop')"><img border="0" src="http://www.mydomain.com/images/ImageName.jpg" width="120" height="130" alt="Image Description"></a>
This example is linking the image on the original page, and will display a larger/close up image. It would work as well for a text link.
In the ImageName.php document, there are 2 pieces of js. Both are placed in the BODY.
<script type="text/javascript">
<!--
window.focus();
//-->
</script>
and
<a href="javascript:window.close();">Close This Window</a>
These bring the popup into focus (on top) and close the popup, respectively.
This document also contains the link to the larger image:
<img border="0" src="http://www.mydomain.com/images/MyBigImage.gif" alt="Image Description">
My popup page is called ImageName.php. You can use html, php, asp.. whatever you like.
Depending on the number of images, yes it can be a lot of coding. I only had 30 or so images to work out.
Professional solution
There might be a simpler method forthcoming. This is, after all, WebmasterWorld.
There is one caveat. I did more than show the larger image on my popup pages. The pages were optimized with content and had a shopping cart link included. As good SE's will do, they began listing my popup pages. Unfortunately, I didn't create a link back to my site, and when I finally did it opened my site in the popup. Very un-cool.
A half-dozen solutions later, I settled on checking the referrer on the popup, and if it wasn't home (my site) then I opened the relevant page instead of the popup. And if you regularly block the referrer in your browser, you can't view those popup image pages. So yes, it got more complicated. A meta NOINDEX directive would have prevented all that, but I really do create pages to get indexed.
.....
href=mylink.href;
window.open(href, windowname, 'width=435,height=550,scrollbars=yes');
....
There is one thing wrong with this solution. gekay states
Target Blank in all those links the result is that every time someone decides he wants to look at a certain picture the jpeg opens in the same window.
The parmeters of the window.open method are url, windowname, and sizing parameters, with windowname being the ID of the window. In your example, this will always be 'pop', and the pics will ALSO open in the same window if the user does not close it.
Add the following to your code and a semi-unique ID (unique enough :0) ) will be generated with each click that will guarantee an actual new window with every click. Also it eliminates one more parameter you'd have to pass to the function. I prefer to pass image size and a title instead, but that's just preference:
var day = new Date(); //Since time marches forward,this
var id = day.getTime(); // id changes with each second.
href=mylink.href;
window.open(href, id, 'width=435,height=550,scrollbars=yes');