Saturday, August 25, 2012

html – JavaScript – select a random page from directory

I\’m developing a webpage but I need a JS script which selects a random page from a directory. At the moment I have this script;



<!-- Hide this script from old browsers --

var links = new Array(10)
links[0] = \"anal.html\"
links[1] = \"brr-fail.htm\"
links[2] = \"anal.html\"
links[3] = \"brr-fail.htm\"
links[4] = \"anal.html\"
links[5] = \"brr-fail.htm\"
links[6] = \"anal.html\"
links[7] = \"brr-fail.htm\"
links[8] = \"anal.html\"
links[9] = \"brr-fail.htm\"
links[10] = \"anal.html\"
function go() {
var a = 1+Math.round(Math.random()*10)
var i = a
location = links[i]
}
// -- End Hiding Here -->

</script>


(Don\’t worry, it isn\’t gay porn – meme)


As you can see, it is kinda complicated, and sometimes it brings up an \”undefined\” page error. Is there any way to make it select a random page from the whole directory? Say something like;


www.urlhere.co.uk/memes/random/


Thanks guys






Rating: 2 out of 5 based on 4 ratings



The post html – JavaScript – select a random page from directory appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-javascript-select-a-random-page-from-directory.html

No comments:

Post a Comment