...

View Full Version : Random Links target.



Gilligan
12-26-2007, 02:44 PM
I'm using a script that opens a random page once the link is clicked on.


<script type="text/javascript">
function randomlinks(){
var randomlink=Math.round(Math.random()*3)
var link=new Array()
link[1]="http://randomlink1"
link[2]="http://randomlink2"
link[3]="http://randomlink3"

window.location=movie[randomlink]
}
</script>

<a href="#" onClick="randomlinks()">Random Link</a>


Now this works fine, but is there a way to get the link to open in a new tab.

I try


<a href="#" onClick="randomlinks()" target="_blank">Random Link</a>

But all that does is open '#' in a new tab. and the random links in the current tab.

Thanks in advance.

A1ien51
12-26-2007, 09:58 PM
Try this instead:



<script type="text/javascript">
var link=new Array()
link[0]="http://randomlink1"
link[1]="http://randomlink2"
link[2]="http://randomlink3"

function randomLinks(elem){
var randomLink=Math.floor(Math.random()*2);
elem.href=movie[randomLink];
}
</script>

<a href="#" onclick="randomLinks(this)">Random Link</a>


Eric

Gilligan
12-27-2007, 01:53 PM
Thanks for the help, but that code isn't working for me.

I used this as a test.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><script type="text/javascript">
var link=new Array()
link[0]="http://www.google.com"
link[1]="http://www.yahoo.co.uk"
link[2]="http://www.msn.com"

function randomLinks(elem){
var randomLink=Math.floor(Math.random()*2);
elem.href=movie[randomLink];
}
</script>

<a href="#" onclick="randomLinks(elem)">Random Link</a>
</body>
</html>

Once i click on the link. Nothing happens

--------------------

With the random link that i am going to use, there will be over 500 links.

A1ien51
12-27-2007, 02:15 PM
sorry about that, I messed up the onclick. should have been "this" and not "elem". I changed the code in my last post.

Eric

Gilligan
12-27-2007, 02:50 PM
It still won't work.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<script type="text/javascript">
var link=new Array()
link[0]="http://randomlink1"
link[1]="http://randomlink2"
link[2]="http://randomlink3"

function randomLinks(elem){
var randomLink=Math.floor(Math.random()*2);
elem.href=movie[randomLink];
}
</script>

<a href="#" onclick="randomLinks(this)">Random Link</a>

</body>
</html>


I click on the link and nothing happens, other than the address bar changes to http://theurl.com#

_Aerospace_Eng_
12-27-2007, 08:44 PM
The array is called link not movie. This works fine

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script type="text/javascript">
var movie=new Array()
movie[0]="http://randomlink1"
movie[1]="http://randomlink2"
movie[2]="http://randomlink3"

function randomLinks(elem)
{
var randomLink=Math.floor(Math.random()*2);
elem.href=movie[randomLink];
elem.target = "_blank";
}
</script>
<a href="#" onclick="randomLinks(this)">Random Link</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum