New window problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New window problem

compuchipcompuchip Posts: 273Member
I am working on a site of a touroperator. For each hotel I am making a page with the hotel information and a number of thumbs. When you click on an image, a new window with the right size opens.
I make the links like this
image

and I have this function
[code]
function openImage(imgFile, title) {
var img = new Image();
img.src = imgFile;
[red] // alert(img.height); [/red]
var imageWindow = open('', '', 'height=' + (img.height + 20) + ', width=' + (img.width+20));
imageWindow.document.open();
imageWindow.document.write("

/" + title + "

");
imageWindow.document.write("image

");
imageWindow.document.close();
img.src = "";
delete img;
}
[/code]

When I click the first image, it works fine: a window pops up with exactly the right size and the image in it.
But when I click the image again, or another one, without reloading the page, I get a window that is much to small and always of the same size.

The strangest thing is, that if I uncomment the line in red, the function works as it should, even with the second, third, ... image.

Please help me out here, because I don't know what I do wrong!

Comments

  • compuchipcompuchip Posts: 273Member
    [b][red]This message was edited by compuchip at 2002-8-29 2:34:18[/red][/b][hr]
    I think I'm having the same problem as someone else who posted here a while ago. The properties of the img variable don't update until AFTER the function has ended.
    So: the window first image is correct
    But: the window of the 2nd image has the proportions of the 1st
    And: the window of the 3rd image has the proportions of the 2nd
    And: the window of the 4th image has the proportions of the 3rd
    etc.

    So, to reformulate the question: does an Image() object has some kind of .Update or .Refresh method?

    ---
    I also tried putting the img.src="image.gif"; and the actual opening of the window in two different functions, hoping the img would update after the end of the 1st but before the start of the 2nd function, but that didn't work either.
  • bgibbybgibby Posts: 251Member
    : [b][red]This message was edited by compuchip at 2002-8-29 2:34:18[/red][/b][hr]
    : I think I'm having the same problem as someone else who posted here a while ago. The properties of the img variable don't update until AFTER the function has ended.
    : So: the window first image is correct
    : But: the window of the 2nd image has the proportions of the 1st
    : And: the window of the 3rd image has the proportions of the 2nd
    : And: the window of the 4th image has the proportions of the 3rd
    : etc.
    :
    : So, to reformulate the question: does an Image() object has some kind of .Update or .Refresh method?
    :
    : ---
    : I also tried putting the img.src="image.gif"; and the actual opening of the window in two different functions, hoping the img would update after the end of the 1st but before the start of the 2nd function, but that didn't work either.
    :

    Honestly, I think the problem is that when there are no WIDTH and HEIGHT values within the Thumbs, the browser makes it's BEST guess.

    Try predefining them with WIDTH and HEIGHT attributes, if that doesn't work, make X amount of arrays that hold [WIDTH, HEIGHT] of each image, if that doesn't work, when you run the array, try making two dummy variables retrieve the WIDTH and HEIGHT of the particular image first. This may cause the Image data to be "updated".

    Either way I believe it's a browser problem (the same as when you can't get a style attribute from anything until it's been rendered, even after the page has been loaded).

    HTH
    Bradley q:)
  • compuchipcompuchip Posts: 273Member
    No, I have a CGI-script which writes the thumbs (with Width + Height)
    But if you click the window I want them to show in their real size.
    Anyway, I solved it by making the window a fixed size large enough to hold images up to 400x400 and use JavaScript to center them in the window.
    Thanks anyway

    : : [b][red]This message was edited by compuchip at 2002-8-29 2:34:18[/red][/b][hr]
    : : I think I'm having the same problem as someone else who posted here a while ago. The properties of the img variable don't update until AFTER the function has ended.
    : : So: the window first image is correct
    : : But: the window of the 2nd image has the proportions of the 1st
    : : And: the window of the 3rd image has the proportions of the 2nd
    : : And: the window of the 4th image has the proportions of the 3rd
    : : etc.
    : :
    : : So, to reformulate the question: does an Image() object has some kind of .Update or .Refresh method?
    : :
    : : ---
    : : I also tried putting the img.src="image.gif"; and the actual opening of the window in two different functions, hoping the img would update after the end of the 1st but before the start of the 2nd function, but that didn't work either.
    : :
    :
    : Honestly, I think the problem is that when there are no WIDTH and HEIGHT values within the Thumbs, the browser makes it's BEST guess.
    :
    : Try predefining them with WIDTH and HEIGHT attributes, if that doesn't work, make X amount of arrays that hold [WIDTH, HEIGHT] of each image, if that doesn't work, when you run the array, try making two dummy variables retrieve the WIDTH and HEIGHT of the particular image first. This may cause the Image data to be "updated".
    :
    : Either way I believe it's a browser problem (the same as when you can't get a style attribute from anything until it's been rendered, even after the page has been loaded).
    :
    : HTH
    : Bradley q:)
    :

Sign In or Register to comment.