如何使网页仅显示一次

如何使网页仅显示一次

本文介绍了如何使网页仅显示一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个HTML和CSS页面,展示了我的Web应用程序的功能.现在,我希望此页面仅为新访客加载.如果回访者访问了我的域,则应将其重定向到网络平台.

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.

本质上,新用户应看到着陆页",而回访用户应被重定向到"Web平台"

Essentially, the new user should see "Landing Page" while a returning user should be redirected to "Web Platform"

如果可能的话,我更愿意使用直接的javascript到我的index.html文件中.我假设LocalStorage可以在这里提供帮助.但老实说,我愿意接受任何解决方案.谢谢.

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.

推荐答案

简单-将以下代码添加到您的目标网页:

Simple - add the following code to your landing page:

if (localStorage.getItem("visited")) {
    window.location.href = "webPlatform.html";
}
localStorage.setItem("visited", "true");

这将检查localStorage变量是否存在-如果存在,则将用户重定向-如果不存在,则设置该变量.

This checks if the localStorage variable exists - if it does, the user is redirected - if not, the variable is set.

这篇关于如何使网页仅显示一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:25