There is site site.ru and there are three site pages: site.ru/1, site.ru/2, site.ru/3. I need to, when opening site.ru/1, the code randomly select between site.ru/2 and site.ru/3 and automatically redirect the user to one of these pages.
1 answer
You can do it on the backend, in the language you use.
You can - on the frontend in js. Like that:
window.location.href = "/" + getRandomInt(2, 3) function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
If you want to go to the page without changing the url - instead of window.location.href = '...';
use window.location.replace('...');
.
And the main question - why do you need it? Split test pages? For split testing there are ready-made and stably working tools.
- oneNo, not for split testing, everything is much simpler, it is part of a web game. Thank you very much for the answer, this is exactly what I need! - A.Hall
|