I have made a HTML and CSS page which showcases the features of my web app. Now I want this page to load only for new visitors. If a returning visitors vists my domain, it should redirect him/her to the web platform.
Essentially, the new user should see "Landing Page" while a returning user should be redirected to "Web Platform"
I would prefer to do it using direct javascript into my index.html file if possible. I am assuming that LocalStorage can help out here. But I am honestly open to any solution. Thanks.
I have made a HTML and CSS page which showcases the features of my web app. Now I want this page to load only for new visitors. If a returning visitors vists my domain, it should redirect him/her to the web platform.
Essentially, the new user should see "Landing Page" while a returning user should be redirected to "Web Platform"
I would prefer to do it using direct javascript into my index.html file if possible. I am assuming that LocalStorage can help out here. But I am honestly open to any solution. Thanks.
Share Improve this question edited Feb 9, 2019 at 22:24 Jack Bashford 44.1k11 gold badges55 silver badges82 bronze badges asked Jan 21, 2019 at 6:27 Drumil PatelDrumil Patel 551 silver badge5 bronze badges 4-
Yes, just set a
localStorage
flag... have you tried anything yourself yet? Please post the code you've tried that isn't working – CertainPerformance Commented Jan 21, 2019 at 6:28 - Possible duplicate of Display Bootstrap Modal First time page loads – smilyface Commented Jan 21, 2019 at 6:31
- Mean time, a simple doubt - After you fix this issue with localStorage, have you think what should happen if a user (who regularly use your website and redirects to another page as you mentioned) takes another browser ? In the new browser he will get the first page and it won't redirect. Is that expected ? The same will happen once he cleared the localStorage/Cache – smilyface Commented Jan 21, 2019 at 6:37
- @smilyface yes, that is expected. – Drumil Patel Commented Jan 22, 2019 at 4:02
1 Answer
Reset to default 20Simple - add the following code to your landing page:
if (localStorage.getItem("visited")) {
window.location.href = "webPlatform.html";
}
localStorage.setItem("visited", "true");
This checks if the localStorage
variable exists - if it does, the user is redirected - if not, the variable is set.