PDA

View Full Version : multiple link popups from diff thumbnails on same page?


newbiedude
09-17-2002, 12:35 AM
Hello -- my first post.

I'd like to use some JS to open popup windows. Example: a visitor clicks on a thumbnail picture (one of several on a page)

I guess I don't fully understand how JS arguments or parameters work. If I have:
<html><head><script>
function openpopup(1){
var popurl="bigthumb1.mgi"
winpops=window.open(popurl,"","width=400,height=338,")
}
function openpopup(2){
var popurl="bigthumb2.mgi"
winpops=window.open(popurl,"","width=400,height=338,")
}
</script></head><body>
pict1<a href="javascript:openpopup(1)"><img src="thumb1.gif"></a>
pict2<a href="javascript:openpopup(2)"><img src="thumb2.gif"></a></body></html>

Why doesn't each href open a unique popup for that selected link? I suppose I am using the openpopup(x) as a variable and I don't see how else to define differences between the two. I'd much like to learn how this is to work (and why the above doesn't so I don't make similar mistakes in the future.

all opinions and ideas are welcome.

thx -- new to JS

glenngv
09-17-2002, 01:45 AM
parameters in a function are variables and variable names don't start with numbers as in your case:
function openpopup(1){ }

you can just have one function for all your thumbnails:

function openpopup(popurl){
winpops=window.open(popurl,"","location=0,width=400,height=338");
winpops.focus();
}


then in your thumbnails:

pict1<a href="javascript: openpopup('thumb1.gif')"><img src="thumb1.gif"></a>
pict2<a href="javascript: openpopup('thumb2.gif')"><img src="thumb2.gif"></a>

that will open each image in a new window even if the same image is already open. if an image is already opened in a new window and the thumbnail of that same image is clicked and you want it to open in that opened window, you have to used this:

function openpopup(popurl,target){
winpops=window.open(popurl,target,"location=0,width=400,height=338");
winpops.focus();
}

then in your thumbnails:

pict1<a href="javascript: openpopup('thumb1.gif','pic1')"><img src="thumb1.gif"></a>
pict2<a href="javascript: openpopup('thumb2.gif','pic2')"><img src="thumb2.gif"></a>

take note of the word javascript, it should have no space.