Web Analytics Made Easy -
StatCounter Pop-up window loads image script - CodingForum

Announcement

Collapse
No announcement yet.

Pop-up window loads image script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pop-up window loads image script

    http://www.pbstar.com/efcomforteam.html
    There is a link to the script in action.

    function newWindow(num) {
    var strToken = new String();
    strToken = "document.Java"+num+".src";
    strToken = eval(strToken);
    var a = strToken.split('_thumb');
    var pic = a[0] + a[1];
    var myImage = new Image();
    myImage.src = pic;
    alert("close pop-up window to return to article");
    var picWindow = window.open(myImage.src,
    "picWin", "width=" + (myImage.width+18) + ", height=" + (myImage.height+25));
    picWindow.focus();

    There is the portion of the script I am concerned with.
    I am using this script to automatically load the full size version of a thumbnailed image into a window. The images on the page have been given the names java1, java2, java3, etc.

    The function calls the image name, gets its src which is imagename_thumb.jpg
    removes the _thumb from the name (that's the part with the call to split() and the combining of arrays a[0] and a[1])

    Then it creates a new image object using the value of pic as the src.

    What is confusing here is that the image.width and image.hieght attributes of the new image object cannot be referenced until the image has loaded. ie. you click on it once and you get a small 70 by 70 px window, but you click on it a second time and since the image has loaded into the browser's cache, the image.width and height attributes are valid and the window is made the proper size.

    Well, that's not really confusing, but this is. If I add in an alert box (which I have) before the window containing the image is opened the window opens to the proper size the first time (or at least it does on my computer).

    Does anyone know why this is? I would like to achieve the same functionality of calling the alert box without actually having to call an alert box to the screen (very annoying).

    This is all in IE by the way. No matter what I do in NS the thumbnail still needs to be clicked on twice to load properly. Not that concerned though since the vast majority of my visitors are IE.

    ps-I've asked questions before about this type of script if it seems familiar.

  • #2
    up

    can anyone help?

    Comment

    Working...
    X