/    Sign up×
Community /Pin to ProfileBookmark

JAVASCRIPT TO REDIRECT INDEX or HOME PAGE

Does anyone know the Javascript for this task:

I have seven different homepage for my site that I’d like to load randomly, so I need an index page that will redirect thusly (ie. to r_home1.htm, r_home2.htm, etc.)

Thanks
R*Well

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JMar 26.2005 — Take a look at this one it could do what you want, maybe

www.huntingground.freeserve.co.uk/scripts/cookies/rdm_redirect.htm
Copy linkTweet thisAlerts:
@phpnoviceMar 26.2005 — Does anyone know the Javascript for this task:[/QUOTE]
What? You didn't like what I posted in the HTML forum for you?
<i>
</i>var pages = new Array(
"index1.htm",
"index2.htm",
"index3.htm",
"index4.htm",
"index5.htm",
"index6.htm",
"index7.htm"
); // no comma after last entry above
self.location.href = pages[Math.floor(Math.random() * pages.length)];
Copy linkTweet thisAlerts:
@RockwellauthorMar 26.2005 — What? You didn't like what I posted in the HTML forum for you?
<i>
</i>var pages = new Array(
"index1.htm",
"index2.htm",
"index3.htm",
"index4.htm",
"index5.htm",
"index6.htm",
"index7.htm"
); // no comma after last entry above
self.location.href = pages[Math.floor(Math.random() * pages.length)];
[/QUOTE]


It looks good -- I just posted here on JS before you put it in the HTML. Thanks and I hear what your saying about JS -- which I guess is more of an issue now because of i.e.

R*Well
Copy linkTweet thisAlerts:
@ExuroMar 27.2005 — A little suggestion for you... It may be a good idea to use the [FONT=Courier New]location.replace()[/FONT] method in this instance since you're doing an immediate redirect. When [FONT=Courier New]location.replace()[/FONT] is called it overwrites the current history entry. This is preferable in cases like this because it doesn't break that back button. I'm sure we've all come across this problem before... You go to a page, then you click Back, but then it just sends you right back to where you were after a second... Anyway, here's the altered code:
var pages = new Array(
"index1.htm",
"index2.htm",
"index3.htm",
"index4.htm",
"index5.htm",
"index6.htm",
"index7.htm"
); // no comma after last entry above
self.location.replace(pages[Math.floor(Math.random() * pages.length)]);

It would be even better if you could do this with an HTTP redirect because then the client wouldn't ever even have to see the blank page. Do you have any server-side scripting support, such as PHP or ASP(.NET)?
×

Success!

Help @Rockwell 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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