Forum Moderators: open

Message Too Old, No Replies

Link Opening In A New Window

         

kristen252

10:25 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



I am installing a banner rotation code on my website and would like to get the links to open up in a new window if possible. I know how to do it in html with the target="_blank", but how could I do it with this piece of javascript?

If anyone could help me out, I would really appreciate it.

Thanks.

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

var currentdate = 0;
var core = 0;

function initArray() {

this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}

link = new initArray(
WEB LINKS GO HERE
);

image = new initArray(
IMAGE LINKS GO HERE
);
text = new initArray(
"3B Graphics",
"Learn HTML in 7 Easy Steps",
"Nic's JavaScript Page"
);

var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];

document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');

//-->
</SCRIPT>

LifeinAsia

10:29 pm on Feb 25, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Did you try something like the following?

document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');

kristen252

3:10 am on Feb 26, 2009 (gmt 0)

10+ Year Member



That works perfectly- thank you so much!