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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop-window inside a for-loop

Status
Not open for further replies.

aaronshover

Programmer
Jan 10, 2003
8
0
0
US
Ok, I have a for-loop that is displaying the pictures that I have in a folder into a table. They are the thumbnails and I have them being linked to the larger pictures. I want the larger pictures (the link)to open up in a pop-up window, where I can specify the height and width and about the toolbars etc... Does anybody know how to do that? I can get it to work withouth the pop-up window script. The code I am using is as follows:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

document.write(&quot;<table border=1 cellpadding=1 cellspacing=3>&quot;);
var pic = 00;
for (j=00;j<05;j++) {
document.write(&quot;<tr>&quot;);
for (k=01;k<04;k++) {
pic++;
document.write('<td>');
document.write('<a href=&quot;#&quot; onClick=&quot;window.open('pictures/'+pic+'.jpg','NewWindow','height=336,width=249');&quot;>
<img src=&quot;pictures/thumbs/'+pic+'.jpg&quot; alt=&quot;Metlab - Potero&quot; width=&quot;150&quot; height=&quot;150&quot; border = 0></a>'); }
document.write(&quot;</tr>&quot;); }
document.write(&quot;</table><br>&quot;);

</script>
 
this line is where you can add window attributes:
[tt]
document.write('<a href=&quot;#&quot; onClick=&quot;window.open('pictures/'+pic+'.jpg','NewWindow','height=336,width=249');&quot;>
<img src=&quot;pictures/thumbs/'+pic+'.jpg&quot; alt=&quot;Metlab - Potero&quot; width=&quot;150&quot; height=&quot;150&quot; border = 0></a>');
[/tt]

you'll need to escape some of your single quotes before this script will work though:
[tt]
document.write('<a href=&quot;#&quot; onClick=&quot;window.open(\'pictures/'+pic+'.jpg\',\'NewWindow\',\'height=336,width=249\');&quot;>'+
'<img src=&quot;pictures/thumbs/'+pic+'.jpg&quot; alt=&quot;Metlab - Potero&quot; width=&quot;150&quot; height=&quot;150&quot; border = 0></a>');
[/tt]

to make it a little easier to manage (less single quotes to escape) i would suggest putting the name and atts in variables, such as:
[tt]
var sName = &quot;NewWindow&quot;;
var sAtts = &quot;height=336,width=249,scrollbars,toolbar&quot;;

document.write('<a href=&quot;#&quot; onClick=&quot;window.open(\'pictures/'+pic+'.jpg\','+sName+','+sAtts+');&quot;>'+
'<img src=&quot;pictures/thumbs/'+pic+'.jpg&quot; alt=&quot;Metlab - Potero&quot; width=&quot;150&quot; height=&quot;150&quot; border = 0></a>');
[/tt]

any window attribute omitted (resizable, statusbar, etc...) will be treated as false.
=========================================================
if (!succeed) try();
-jeff
 
Thanks a lot, it doesn't error out, but it doesn't open up a pop-up window either, it looks as though it did in the address bar of the window, but nothing happens. Any thoughts? I have put the page up on the Net if you want to look at it to see what it's doing. It won't be up until a little past 9, like maybe 9:15. Here's the link:
 
Here is the error I get when I click on the thumbnails:
Line 310
Char 1
Error: &quot;NewWindow&quot; is undefined
 
looks like i forgot to escape some quotes myself...try this:
[tt]
var sName = &quot;NewWindow&quot;;
var sAtts = &quot;height=336,width=249,scrollbars,toolbar&quot;;

document.write('<a href=&quot;#&quot; onClick=&quot;window.open(\'pictures/'+pic+'.jpg\',\''+sName+'\',\''+sAtts+'\');&quot;>'+
'<img src=&quot;pictures/thumbs/'+pic+'.jpg&quot; alt=&quot;Metlab - Potero&quot; width=&quot;150&quot; height=&quot;150&quot; border = 0></a>');
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Thank you so much, I posted this on many other forums and had about 15-20 answers, but nobody could get it to work.
Thanks again,
Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top