0

I just wanted to know how I can create a button that can take a person to multiple websites in a random order when it is clicked each time. I plan on using this button for a toolbar that I'm planning to create, and the outline that is provided for the HTML component looks like this:

<html>
<head>
<!--
Uncomment out the below script reference as needed.  For more information on using the API, please consult http://www.conduit.com/Developers/overview.aspx
<script language="JavaScript" src="http://api.conduit.com/BrowserCompApi.js"></script>
-->
<style type= "text/css">
<!--
BODY {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0;
width:100%;height:100%;overflow:hidden;background-color:threedface;}
-->
</style>
</head>
<body>

<!-- ENTER YOUR HTML HERE -->

</body>
</html>

Is there any way that I can do this by using this outline? Thanks in advance.

Kayla Brown
  • 1
  • 1
  • 2

4 Answers4

1

As suggested by others, simply make a button click call a function that picks a random site from an array. Here is an explanation on how to pick a random element from a Javascript array.

Example implementation:

<script type="text/javascript">
    var websites = ["http://google.com", "http://reddit.com", "http://stackoverflow.com"];

function randomWebsite() {
    var website = websites[Math.floor(Math.random()*websites.length)];
    window.location = website;
}
</script>

<button type="button" onclick="randomWebsite();">Random website</button>
Community
  • 1
  • 1
Niklas Lindblad
  • 1,031
  • 6
  • 9
0

I'm not going to write the script for you but you'd want to use javascript to do this. Use the random function and assign your website urls to an appropriate number.

Example:

if you had three total websites then you'd do the random function and assign 0-.33 website 1, .34 - .66 website2, and .67 - 1 website 3.

Chad
  • 492
  • 5
  • 14
0

I think you need javascript to do this, Take a look on this page maybe this can help you

http://ozirock.hubpages.com/hub/How-to-make-a-Random-Page-button-for-your-website

user229044
  • 232,980
  • 40
  • 330
  • 338
KevinKuijer
  • 35
  • 1
  • 1
  • 7
0

You need Javascript for that.

You can have a list of websites. You can get the website you will go to, when the button is clicked, by using the random function in javascript. Here is the example when using an array, Getting a random value from a JavaScript array

Hope it helps.

We shouldn't give you any code, as you didn't provide anything. But your algorithm should follow what I mentioned.

Community
  • 1
  • 1
Jeremy D
  • 4,787
  • 1
  • 31
  • 38