samedi 18 mai 2019

How can I redirect users to different website variant based on last used variant?

I have 2 variants of my website (say, A & B). They're stored on the server at /a/ & /b/.

On my home page (/index.html), I wanna give users the option to choose (mostly a button) which variant to visit.

Then, I want to set that variant as the default for the user, so, the next time, the user tries to visit index.html, he/she will be redirected to the last visited variant.

Both the variants will have toggles to switch to the other one. So, if a user switches to the other one (say B from A), I'd like to set the new one (B) as the default so that the user gets redirected to the new one (B) next time he/she visits /index.html.

The redirects are supposed to work only on the /index.html page, so that if the users visit the variant specific webpage by directly typing the URL, they don't get redirected. However, the preferences should get changed, i.e., if last time the user had visited variant A and now, has used the URL of variant B, the next time he/she visits /index.html, he/she should be redirected to B.

I am making a wild guess by saying that cookies and JavaScript can help me achieve this.

Can someone tell me if and how I can achieve this?




Aucun commentaire:

Enregistrer un commentaire