...

View Full Version : Random Website Link



aseylys
04-02-2011, 07:30 PM
Hello,

I'm looking for a link to place into my site that, when clicked, redirects the user to a random website in a list of websites that I have.

Now, I have a CSS code that does exactly that, but it's in the form of a button. I just need a plain text link. I'm not too fluent in CSS.

Can anyone help me?


Here's the code that I have currently:

<script>
<!--

var randomlinks=new Array()

randomlinks[0]="http://freewarejava.com"
randomlinks[1]="http://javascriptkit.com"
randomlinks[2]="http://dynamicdrive.com"
randomlinks[3]="http://cnn.com"
randomlinks[4]="http://www.geocities.com"

function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
</script>
<form>
<p><input name="B1" type="submit" onclick="randomlink()" value="Random Site" readonly="readonly"></p>
</form>

SB65
04-02-2011, 07:51 PM
I'm pretty sure you can't render a form input as a text link, but here a simple link would do the job:


<a href="#" onclick="randomlink()">Random link</a>

bullant
04-03-2011, 08:02 AM
Something like this.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var urls = ['url1','url2','url3','url4','url5','url6'];
window.onload=function(){
document.getElementById('lnk1').onclick=function(){
this.href = urls[Math.floor(Math.random()*urls.length)];
}
}
</script>
</head>
<body>
<div>
<a href="" id="lnk1">Click me</a>
</div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum