...

View Full Version : Javascript question.



Mrleone
09-20-2005, 01:59 PM
Hey guys!
I use this script on my site for banners and pics to rotating:


<script language="JavaScript">
<!--
/*
Random Image Link Script- By Website Abstraction(http://www.wsabstract.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="http://www.yoursite.com/pics/pic.jpg"
myimages[2]="http://www.yoursite.com/pics/pic.jpg"
myimages[3]="http://www.yoursite.com/pics/pic.jpg"
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.yoursite.com"
imagelinks[2]="http://www.yoursite.com"
imagelinks[3]="http://www.yoursite.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>

The only problem is, I want all the sites to open in a new window..
I try to ad an "blank" code in the html codes but then all my links in the site opens in a new window.. I want only the urls in this rotating code to open..

How?

Thanks in advance!

Bill Posters
09-20-2005, 02:56 PM
e.g.

<script type="text/javascript">

function random_imglink() {

var myimages = new Array();
myimages[1] = "http://www.yoursite1.com/pics/pic.jpg";
myimages[2] = "http://www.yoursite2.com/pics/pic.jpg";
myimages[3] = "http://www.yoursite3.com/pics/pic.jpg";

deadwood = myimages.splice(0,1); // remove the [0] index element from this array

var imagelinks = new Array();
imagelinks[1] = "http://www.yoursite1.com";
imagelinks[2] = "http://www.yoursite2.com";
imagelinks[3] = "http://www.yoursite3.com";

deadwood = imagelinks.splice(0,1); // remove the [0] index element from this array

var ry = Math.floor(Math.random()*myimages.length);

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

}

random_imglink();

</script>

HTH :)

Mrleone
09-20-2005, 04:02 PM
Aaaaah, excellent...

Thanks!! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum