简体   繁体   English

如何让网页只显示一次?

[英]How do I make a web page show up only once?

I have made a HTML and CSS page which showcases the features of my web app.我制作了一个 HTML 和 CSS 页面,展示了我的网络应用程序的功能。 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"本质上,新用户应该看到“登陆页面”,而返回用户应该被重定向到“Web平台”

I would prefer to do it using direct javascript into my index.html file if possible.如果可能的话,我宁愿直接使用 javascript 到我的 index.html 文件中。 I am assuming that LocalStorage can help out here.我假设 LocalStorage 可以在这里提供帮助。 But I am honestly open to any solution.但老实说,我对任何解决方案持开放态度。 Thanks.谢谢。

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.这将检查localStorage变量是否存在 - 如果存在,则重定向用户 - 如果不存在,则设置变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM