Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

popup inconsistency

Status
Not open for further replies.

lesm

Technical User
Jun 11, 2002
6
PE
I'm not expert, just a learning by doing novice.

I use this script to popup an image. It works as expected except that every now and then, the picture fails to show up showing a big blank window. I see no pattern as to why and when this script fails and also I see no other way to do the job.

The idea is to popup perfectly framed images using several links to pictures located at another of my sites.

Any help will be appreciated.

<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
var win=null;
function showimage(url_image,picname){
var img = new Image();
var scrwidth = screen.availWidth;
var scrheight = screen.availHeight;
img.src = url_image;
win=window.open('','','width='+img.width+',height='+img.height+',scrollbars=no, dependent=yes,resizable=1,left=' + ((scrwidth) * .55) + ',top=' + ((scrheight) * .15) + ',toolbar=0');
win.document.write ('<html>\n');
win.document.write (' <head>\n');
win.document.write (' <title>'+picname+'</title>\n');
win.document.write (' </head>\n');
win.document.write (' <body leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot;>\n');
win.document.write (' <img src=&quot;' + url_image + '&quot; height='+img.height+' width='+img.width+'>\n');
win.document.write (' </body>\n');
win.document.write ('</html>\n');
}
</script>


<a href=&quot;javascript:showimage(' src=&quot;/graphics/pic.gif&quot; alt=&quot;Show image&quot; width=&quot;21&quot; height=&quot;21&quot; border=&quot;0&quot;></a>
 
try passing in the image location as the popup windows url instead of writing to the window so you only need your window.open to:

win=window.open(url_image,'','width='+img.width+',height='+img.height+',scrollbars=no, dependent=yes,resizable=1,left=' + ((scrwidth) * .55) + ',top=' + ((scrheight) * .15) + ',toolbar=0');
 
I had some similar script once and want to recommend you the following:

1. I'd rather pass image w/h as parameters to showimage function
if you don't want this, then
2. add &quot;name&quot; attribute to the <img> tag:
<img ... name='pass'>
it is not there now and this is probably the reason why you don't see an image

3. delete all those '\n' as they are useless.

4. the proper way to write the contents of a document is to open the document stream first, and then close it:
win.document.open();
win.document.write();
. . .
win.document.close();

good luck
 
sjravee,

Same thing. I also noted that as soon as the image is loaded it never fails. So, preloaded is an option, however the pics are 15K to 40K and some 15 per page, so chances are that when the user clicks an image that particular image is not loaded yet.
 
Why not start caching the images after the page load event, at least then the user doesnt have to wait for all the images to downlaod to see the actual page
 
Starway,

I did all what you recommend and still doesn't work. The behaviour is something like:

click img 1 ok
click img 2 ok
click img 3 ok
click img 4 fail
click img 5 fail
click img 5 ok
and things like that.

It's something like there is no room to store pictures unless you click twice after the room is filled. The worst thing is that there is no a defined pattern. It's randomly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top