/    Sign up×
Community /Pin to ProfileBookmark

Random page generator

Hi Guys,

On my site I want to have a script so that when you go to [url]www.nameofmysite.com[/url] the script in that< head> loads in a random page.

ie, when I go to [url]www.nameofmysite.com[/url] it could load:

either
[url]www.nameofmysite.com/page1.html[/url]
or
[url]www.nameofmysite.com/page2.html[/url]
or
[url]www.nameofmysite.com/page3.html[/url]

Is there a script that does this. I know it can be done with one image using javascript, but I want it to call a random page, not just images?

Can anyone point me in the right direction or post a url to a script?

Thanks

Chris

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarJun 22.2005 — [code=php]<script type="text/javascript"><!--
var pages = ["page1.html", "page2.html", "page3.html", "page4.html"];
window.top.location.href = pages[Math.floor(Math.random()*pages.length))];
//-->
</script>[/code]
Copy linkTweet thisAlerts:
@chrisbauthorJun 22.2005 — Thanks, but that throws up as javascript error - any ideas?

Thanks
Copy linkTweet thisAlerts:
@scragarJun 22.2005 — I closed one too many brackets, sorry:

[code=php]<script type="text/javascript"><!--
var pages = ["page1.html", "page2.html", "page3.html", "page4.html"];
window.top.location.href = pages[Math.floor(Math.random()*pages.length)];
//-->
</script>[/code]
×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...