[thelist] pop up window for image without MSIE image resize feature?

James Aylard evolt at pixelwright.com
Fri Sep 13 15:23:01 CDT 2002


Tony,

> I *can* create static container pages, since the whole thing is database
> driven, but i'd rather not if I don't have to.
>
> has anyone got a pop up script that would take the name of the image I
> want from the originating page, wrap it in html and open it in a pop up
> window?

    Although I replied to you off-list in response to your css-d post, I'll
reiterate and elaborate here since you provide a bit of extra information.
There are two approaches that you can use: Javascript, doing a
document.write into a new window, or server-side using a single, generic
image-holding page.
    Although most UAs support Javascript, and most users run their browsers
with scripting enabled, I don't recommend the Javascript approach because it
provides little extra benefit while unnecessarily shutting some users out of
the loop. A simplified example of the Javascript approach:

<script type="text/javascript">
  function fnPopWin(vSrc)
  {
    var win ;
    win = window.open() ;
    win.document.open() ;
    win.document.write('<html><head><title>Image</title></head>' +
      '<body><img src="' + vSrc + '"></body></html>') ;
    win.document.close() ;
  }
</script>

    I do recommend a server-side approach, whereby you pass to the target
page, as part of a querystring, a reference to the image you want to open.
Keep in mind that you need only _one_ page into which you pop the images;
your server-side scripting sets the src of the image based on the value of
the querystring that you pass to it:

<!-- Thumbnail page -->
<script type="text/javascript">
  function fnPopWin(vHref,vTarget)
  {
    var win ;
    win = window.open(vHref,vTarget) ;
  }
</script>
<p><a href="MyImg.asp?imgSrc=NewBaby.png"
    target="_blank"
    onclick="fnPopWin(this.href,this.target);"
    ><img src="NewBabyThumbnail.png"></a></p>

<!-- Image-container page (assuming ASP) -->
<%
  Dim strImgSrc, strSrc
  strImgSrc = Request.QueryString("imgSrc")
  strSrc = "Images/" & strImgSrc
  Response.Write "<img src=""" & strSrc & """>"
%>

    Very simplified examples that can be easily expanded to provide
additional functionality, but that's the gist of it.

James Aylard





More information about the thelist mailing list