mrbigbob
mrbigbob

Reputation: 1

Directing Users to One of Random pages when page load

I am building an HTML web application but I need a little help. I have it linked to a launch page. But this is the part that I need help with, how can I redirect users to different pages. Say I had the following pages as random redirects:

b/b1.html b/b2.html b/b3.html b/b4.html b/b5.html

I want the user to get directed to just one of those. I know how to insert a standard html redirect.

I would appreciate it if any of you had any code samples. Thanks

Upvotes: 0

Views: 41

Answers (1)

James Wakefield
James Wakefield

Reputation: 526

This very quick solution the urls variable is just a space separated array which can be any url, if you need it to be absoulute instead of relative put in the full url including the https://blah.com part

var urls='b/b1.html b/b2.html b/b3.html b/b4.html b/b5.html'.split(' ')
window.location=urls[Math.floor(Math.random()*urls.length)]

Upvotes: 1

Related Questions