Opening with a random link

Tedi_84

Active Member
Greetings. How to do it opening a random link from many?

Example:

<html>
<head>
<script type="text/javascript">
<!--
// Create an array of the links to choose from:
var links = new Array();
links[0] = "http://www.link1.com/";
links[1] = "http://www.link2.com/";
links[2] = "http://www.link3.com/";
links[3] = "http://www.link4.com/";


function openLink() {
// Chooses a random link:
var i = Math.floor(Math.random() * links.length);
// Directs the browser to the chosen target:
parent.location = links;
return false;
}
//-->
</script>
</head>
<body>
</html>

I want to open one of the integrated links on every reload.
 
Последно редактирано от модератор:
Opening with a random link - Javascript

The example above is working fine, the only thing you have to do is call the openLink() function at the bottom of the script.
The only disadvantage of the example code is that the link will be opened in the same window.
 
Последно редактирано:
Opening with a random link - Javascript

Is there any function? Would you give me an example?
 
Последно редактирано от модератор:
Opening with a random link - Javascript

The function has only been declared but you have to call it in order to execute it. Try the example below.

Код:
function openLink() {
// Chooses a random link:
var i = Math.floor(Math.random() * links.length);
// Directs the browser to the chosen target:
parent.location = links[i];
return false;
}

[B]openLink();[/B]

//-->
</script>
</head>
<body>
</html>
 
Последно редактирано:

Горе