PDA

View Full Version : random url redirect



MstrJ23
01-23-2009, 04:12 PM
I'm new to java script and looking for a way to (automatically) and randomly redirect a user to one of a list of urls after going to the redirect page.

eg.

user is sent to /redirect.htm

instantly then sent to either page1 page 2 or page 3 randomly (or if possible based off a percentage)

so page1 (30% of the time); page 2 (50%); page 3 (20%)

any help would be greatly appreciated

jscheuer1
01-23-2009, 04:44 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
(function(n){
var pages = ['page1.htm', 'page2.htm', 'page3.htm'];
n = n < 3? 0 : n < 8? 1 : 2;
window.location.replace(pages[n]);
})(Math.floor(Math.random() * 10));
</script>
</head>
<body>

</body>
</html>