3

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.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • Yes, just set a `localStorage` flag... have you tried anything yourself yet? Please post the code you've tried that isn't working – CertainPerformance Jan 21 '19 at 06:28
  • Possible duplicate of [Display Bootstrap Modal First time page loads](https://stackoverflow.com/questions/16596429/display-bootstrap-modal-first-time-page-loads) – smilyface Jan 21 '19 at 06: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 Jan 21 '19 at 06:37
  • @smilyface yes, that is expected. – Drumil Patel Jan 22 '19 at 04:02

1 Answers1

20

Simple - 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.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • Hey Jack, thanks for the code. I will be replacing webPatform.html with a URL since the user needs to be redirected to an Angular Web App.I'll shoot you an update once I get it working. – Drumil Patel Jan 22 '19 at 04:04