You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现用户访问指定页面达3个后才显示新增网页链接?

实现步骤

1. 给每个地点页面添加访问标记

在sheriff.html、saloon.html、stables.html、clocktower.html、bank.html、store.html这六个页面的**</body>标签之前**,分别添加对应代码标记用户访问记录:

比如sheriff.html里加:

<script>
// 标记用户已访问警长办公室页面
localStorage.setItem('visited_sheriff', 'true');
</script>

saloon.html里换成:

<script>
localStorage.setItem('visited_saloon', 'true');
</script>

剩下四个页面以此类推,把visited_后的字段换成对应页面名称(比如visited_stables、visited_clocktower等)即可。

2. 在places.html中设置墓地链接的显示逻辑

在places.html现有链接的下方,添加这段代码:

<!-- 默认隐藏墓地链接 -->
<div id="graveyard-link" style="display: none;">
  <a href="graveyard.html">墓地</a>
</div>

<script>
// 列出所有需要检查的页面标记
const visitedList = [
  localStorage.getItem('visited_sheriff'),
  localStorage.getItem('visited_saloon'),
  localStorage.getItem('visited_stables'),
  localStorage.getItem('visited_clocktower'),
  localStorage.getItem('visited_bank'),
  localStorage.getItem('visited_store')
];

// 统计已访问的页面数量
let visitedCount = 0;
for (let i = 0; i < visitedList.length; i++) {
  if (visitedList[i] === 'true') {
    visitedCount++;
  }
}

// 满足条件则显示墓地链接
if (visitedCount >= 3) {
  document.getElementById('graveyard-link').style.display = 'block';
}
</script>

补充说明

  • localStorage是浏览器自带的本地存储工具,能把小数据存在用户浏览器中,关闭浏览器后记录也不会消失(除非用户手动清除缓存)。
  • 每个页面被访问时会在localStorage里存一个标记,places.html读取这些标记统计数量,达到3个就自动显示墓地链接。
  • 代码要放在</body>标签前,确保页面元素加载完成后再执行判断逻辑。

内容的提问来源于stack exchange,提问作者neuro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 11:30:06