ttmt — 2010-08-09T04:30:35-04:00 — #1
I have a simple a tag in html that when clicked I want to link to a random address picked from an array of possible links.
So in the code here I have an array of the links and I'm picking a random number from the length of that array, I'm then using that number to pick a random link from the array.
var links_arr = ["http://www.link1.com","http://www.link2.com","http://www.link3.com","http://www.link4.com"]
var ranNum = Math.floor(Math.random()*links_arr.length)
var linkTo = links_arr[ranNum];
This all works fine and the window.alert show randomly picked links from the array.
The problem is passing the link to the href of the a tag - how can I use the link in the href ?
ttmt — 2010-08-09T05:25:07-04:00 — #2
When the person clicks the link.
I can pick the link randomly, it was just passing it to the a tag
paul_wilkins — 2010-08-09T04:48:20-04:00 — #3
Do you want the link to get the random link before the person clicks on it, or do you want the random link to be chosen when the person clicks on the link?
Tip: the second option is a lot easier to do.
guido2004 — 2010-08-09T04:38:58-04:00 — #4
paul_wilkins — 2010-08-09T06:19:59-04:00 — #5
In that case you just want to set window.location to the new link.