如何让网页显示只有一次?

问题描述 投票:2回答:1

我做了,展示了我的web应用程序的功能HTML和CSS页面。现在,我想这个页面只加载新的访问者。如果回访者vists我的域名,应该她重定向他/到网络平台。

从本质上讲,新的用户会看到“着陆页”,而回归用户应该被重定向到“Web平台”

我宁愿直接使用到的JavaScript如果可能的话我的index.html文件来做到这一点。我假设的localStorage可以帮助在这里。但我对任何解决方案诚实开放。谢谢。

javascript html css html5 webpage
1个回答
19
投票

简单 - 下面的代码添加到您的着陆页:

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

这用来检查localStorage变量存在 - 如果这样做,将用户重定向 - 如果不是,该变量设置。

© www.soinside.com 2019 - 2024. All rights reserved.