PDA

View Full Version : Opeining link for random pictures in new window...



drluv
02-15-2014, 03:22 AM
I tried to read as many posts as I could find on this topic but did not see any that answered the question I was looking for. Bottom line is that I use the random picture generator below and it works great. It allows you to link the pictues to specific websites which is exactly what I wanted to do. However, I'm having a very difficult time trying to find a way to open these links in a new window when the pictures are clicked on. Can anyone help?

Thanks in advance...


<SCRIPT LANGUAGE="Javascript">
function banner() { } ; b = new banner() ; n = 0
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner2.jpg' border='0' ALT='Haunted House'></A>"
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner3.jpg' border='0' ALT='Graves in the Snow'></A>"
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner4.jpg' border='0' ALT='Insane Joker'></A>"
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner5.jpg' border='0' ALT='Fangs'></A>"
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner6.jpg' border='0' ALT='Screaming Clowns'></A>"
b[n++]= "<A HREF='index.html'><IMG name=randimg SRC='images/interface/banner7.jpg' border='0' ALT='Dead Servant'></A>"
i=Math.floor(Math.random() * n) ;
document.write( b[i] )
</SCRIPT>

jscheuer1
02-15-2014, 03:55 AM
If you only want certain ones to open in a new window/tab, you can add the attribute target='_blank' to the a tag for those, ex:


b[n++]= "<A HREF='index.html' target='_blank'><IMG name=randimg SRC='images/interface/banner2.jpg' border='0' ALT='Haunted House'></A>"

If you want all of them to open in a new window/tab, you can add that to all of them. Or you can leave them as is and change:


document.write( b[i] )

to:


document.write( b[i].split("A H").join("A target='_blank' H") )

drluv
02-15-2014, 02:36 PM
Thanks for the quick response. The code is Perfect.

Thanks!!!