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

Problem with script. What's wrong?

Status
Not open for further replies.

Endbringer

Technical User
Jan 18, 2002
28
US
I'm trying to use Javascript to open a window showing a picture along with a close link.I have many pictures and want to know if one javascript function can open them up.I've tried the following, but i can't get it to work.Any help would be appreciated.

<script LANGUAGE=&quot;JavaScript&quot;>
var pic0 = &quot;carroll1.gif&quot;
var pic1 = &quot;carroll2.gif&quot;

function picWin(pic){
myWin = window.open(&quot;&quot;,&quot;myWin&quot;)
imgName.src = pic
myWin.document.write(&quot;<html><body>
<img src='imgName'></body></html>&quot;)
}
</script>


Here are two of the links that i'm trying to get to work.

<a CLASS=&quot;pic&quot; href=&quot;javascript:picWin(pic0)&quot; target=&quot;Main&quot;>[Pic #1] </a>
<a CLASS=&quot;pic&quot; href=&quot;javascript:picWin(pic1)&quot; target=&quot;Main&quot;>[Pic #2] </a>
 
function picWin(pic){
myWin = window.open(&quot;&quot;,&quot;myWin&quot;)
imgName = pic
myWin.document.write(&quot;<html><body>
<img src='&quot;+imgName+&quot;'></body></html>&quot;)
}
adam@aauser.com
 
this worked for me (tested in IE5.5):

<script>


function picWin(pic){
myWin = window.open(&quot;&quot;,&quot;myWin&quot;)
myWin.document.write(&quot;<html><body><img src=&quot;+pic+&quot;></body></html>&quot;)
return false
}

</script>
<a CLASS=&quot;pic&quot; href=&quot;#&quot; onClick=&quot;picWin('carroll1.gif')&quot;>[Pic #1] </a>
<a CLASS=&quot;pic&quot; href=&quot;#&quot; onClick=&quot;picWin('carroll2.gif')&quot;>[Pic #2] </a> jared@aauser.com
 
Much the same as I do it, but I call the function from the onClick handler of the image itself, which takes even less thought!

<IMG SRC=&quot;images/mypic.jpg&quot; onClick=&quot;picWin(this);&quot;>


Greg.
 
i dont think netscape supports onclick of images. adam@aauser.com
 
a CLASS=&quot;pic&quot; href=&quot;javascript:picWin(pic0)&quot; target=&quot;Main&quot;>[Pic #1] </a>
<a CLASS=&quot;pic&quot; href=&quot;javascript:picWin(pic1)&quot; target=&quot;Main&quot;>[Pic #2] </a>

plus, i dont see images in here. the images are to be in the new window. adam@aauser.com
 
I tried the first two ways, and only the second one works. I kinda wanted the first way to work, to keep the typing down, but the second one worked fine. Thanks for the help!


Robert
Endbringer42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top