JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
New window problem Posted by compuchip on 29 Aug 2002 at 2:13 AM
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
<A HREF="javascript:openImage('somehotel.gif');"><IMG SRC='somehotel.gif'></A>

and I have this function
function openImage(imgFile, title) {
 var img = new Image(); 
 img.src = imgFile; 
 // alert(img.height); 
 var imageWindow = open('', '', 'height=' + (img.height + 20) + ', width=' + (img.width+20)); 
 imageWindow.document.open();
 imageWindow.document.write("<HTML>\n<HEAD>\n<TITLE>/" + title + "</TITLE></HEAD>\n<BODY BGCOLOR=\"#FEFEEA\" ");
 imageWindow.document.write("LEFTMARGIN=10 TOPMARGIN=10 RIGHTMARGIN=10 BOTTOMMARGIN=10>\n ");	
 imageWindow.document.write("<IMG SRC=\"" + imgFile + "\">\n</BODY>\n</HTML>");
 imageWindow.document.close(); 
 img.src = "";
 delete img;
} 


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!
Report
Re: New window problem Posted by compuchip on 29 Aug 2002 at 2:29 AM
This message was edited by compuchip at 2002-8-29 2:34:18

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.
Report
Re: New window problem Posted by bgibby on 29 Aug 2002 at 5:24 PM
: This message was edited by compuchip at 2002-8-29 2:34:18

: 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:)
Report
Re: New window problem Posted by compuchip on 30 Aug 2002 at 4:05 AM
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

: : This message was edited by compuchip at 2002-8-29 2:34:18

: : 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:)
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.