![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have huge page of links, to whcih I am currently adding. I would like to add a "random link" button which would parse the current page, extract all URLs then load a random link. Before I start to code, does such s thing already exist. Thanks in advance... |
#3
| |||
| |||
|
|
"Papa Legba" wrote I have huge page of links, to whcih I am currently adding. I would like to add a "random link" button which would parse the current page, extract all URLs then load a random link. Hi, such scripts already exist for the most purposes. Displaying random quotes, links, images, etc. A start is to look through the category: Randomizing, at hotscripts.com http://www.hotscripts.com/PHP/Script...ing/index.html Most scripts I've come across use a mysql database as background, but if you search enough, you'll find scripts that use normal text-files as base. |
#4
| |||
| |||
|
|
I don't see the need for anything serverside, especially not for databases, when the page is already in the browser. These two lines of javascript do the job perfectly on any page: var a = document.links; location.href = a[ Math.floor( a.length*Math.random() ) ]; If the page contains lots of '#' or 'mailto' or other strange links, you may want to go the extra mile and filter them out: var a = document.links, x ; while ( !x || x.href.indexOf('http') !== 0 ) { x = a[ Math.floor( a.length * Math.random() ) ]; } location.href = x; |
#5
| |||
| |||
|
|
Don, that seems incredible. I have almost hacked it in PHP, but it is much longer. Can you tell me how to refernce that from HTML (sorry, I am not a JS person). Thanks again. |
)![]() |
| Thread Tools | |
| Display Modes | |
| |