PDA

View Full Version : target="_blank" problem



Fancy Dan
11-06-2005, 03:23 PM
When using the random image script as below, how can i get the link to open in a blank window as opposed to opening in the parent window which is the default?

<script language="JavaScript">
<!--

function random_imglink(){
var myimages=new Array()

myimages[1]="images/aloe_advert.gif"
myimages[2]="images/2.gif"
myimages[3]="images/3.gif"
myimages[4]="images/4.gif"
myimages[5]="images/5.gif"
myimages[6]="images/6.gif"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.flpireland.com"
imagelinks[2]="http://www.netscape.com"
imagelinks[3]="http://www.microsoft.com"
imagelinks[4]="http://www.dynamicdrive.com"
imagelinks[5]="http://www.freewarejava.com"
imagelinks[6]="http://www.cnn.com"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
//-->
</script>

Twey
11-06-2005, 04:12 PM
Change:

document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
to

document.write('<a target="_blank" href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')

Fancy Dan
11-06-2005, 09:24 PM
cheers and beers to you fella! :D