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... 4 2458
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
Another tip is to google for something like: PHP Code Display random link http://www.google.com/search?hl=en&l...nk&btnG=Search
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.
You'll most likely need to reorganize you link collection, in order to make
it work "out of the box" with finished scripts.
-Geir
"Papa Legba" <Pa************@gmail.com> wrote in message news:39**************************@posting.google.c om... 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...
"Geir Andersen" wrote "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.
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;
hth
--
Ivo
"Ivo" <no@thank.you> wrote in message news:<422737f3$0$9747 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;
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.
"Papa Legba" wrote 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.
<script type="text/javascript">
function randomlink() {
var a = document.links, x ;
while ( !x || x.href.indexOf('http') !== 0 ) {
x = a[ Math.floor( a.length * Math.random() ) ];
}
location.href = x;
return false;
}
</script>
<p><a href="#" onclick="return randomlink();">Random link</a></p>
There is one caveat: on a page with nothing but "#" links the 'while' loop
will never end, freezing your browser, watch out that. For example, don't
try the above in a blank document like I did, but be sure to include some
links too :))
--
Ivo This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bhennon |
last post by:
Hey all,
I have a small php script that calls a random image at the following
page.
http://www.2006ymcanationals.com/random.php
IT WORKS IF I go directly to the above link.
I am trying to...
|
by: Heath |
last post by:
Using MSIE 5+ Heath writes:
My problem deals with working with window objects between
pages as follows:
My Introduction page contains a link to my Action page.
The onClick of that link...
|
by: timmy_dale12 |
last post by:
I need help with this one. I have a function that pastes a row. In
each row i am pasting a link which is to call a date picker javascript
function. This is the code that pastes the link :
link =...
|
by: Papa Legba |
last post by:
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...
|
by: Rod Snyder |
last post by:
I'm trying to set up a page with an asp.net link button that would send a
user to a certain page and on page load execute a specific stored procedure
tied to the button on the previous page. The...
|
by: tshad |
last post by:
I am trying to set up an Image authorization where you type in the value
that is in a picture to log on to our site.
I found a program that is supposed to do it, but it doesn't seem to work.
...
|
by: John Fairhurst |
last post by:
Hi,
The following code should select the specified number of records randomly
from the database
<%
....
query = "SELECT FROM "
Set RS = Server.CreateObject("ADODB.Recordset")
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I generate a random integer from 1 to
N?...
|
by: pt36 |
last post by:
Hi
I have a page with a form and a textbox.
before to submit the form I want to chek if the inserted value in the
textbox is already present in a database.
So I need to pass the textbox value...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |