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

如何仅用HTML/CSS/JS实现禁止主站访问的网站即将上线预告页

实现方案

方案1:临时入口替换法(最简单,适合开发阶段快速部署)

该方案无需修改现有业务代码,操作成本最低:

  • 把当前主站的入口文件(一般为index.html)重命名为dev_index.html,开发阶段你自己访问该路径即可正常调试
  • 将写好的「即将上线」预告页命名为index.html,放在站点根目录,普通用户访问域名默认就会打开预告页
  • 站点正式上线时,直接删除预告页的index.html,把dev_index.html改回index.html即可完成切换

注意:该方案无法阻止用户手动输入已知的主站页面路径访问,如果需要完全拦截所有主站内容,可使用方案2。

方案2:全局访问拦截(完全禁止访问主站内容)

在所有主站HTML文件的<head>标签最顶部插入以下JS代码,用户访问任意主站页面都会自动跳转到预告页:

<script>
// 只有带dev=1查询参数时可以访问主站,你自己调试时访问xxx.html?dev=1即可
if (!window.location.search.includes('dev=1')) {
  window.location.href = '/coming-soon.html';
}
</script>

操作步骤:

  • 把预告页命名为coming-soon.html放在站点根目录
  • 根目录的index.html可以直接用预告页内容,也可以加上述跳转逻辑
  • 站点正式上线时删除所有页面的拦截代码即可

无计时器「即将上线」预告页示例代码

纯原生实现,无任何依赖,可直接复制使用:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>即将上线 - 你的站点名称</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background-color: #f5f5f5;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      color: #333;
      padding: 20px;
    }
    .logo {
      font-size: 32px;
      font-weight: bold;
      margin-bottom: 32px;
      color: #2563eb;
    }
    h1 {
      font-size: 48px;
      margin-bottom: 16px;
      text-align: center;
    }
    .desc {
      font-size: 18px;
      color: #666;
      margin-bottom: 40px;
      text-align: center;
      max-width: 600px;
    }
    .contact {
      font-size: 16px;
      color: #888;
    }
  </style>
</head>
<body>
  <div class="logo">你的站点Logo</div>
  <h1>即将上线</h1>
  <p class="desc">我们正在努力准备内容,很快就会和大家见面,敬请期待。</p>
  <p class="contact">联系我们:xxx@xxx.com</p>
</body>
</html>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 03:06:06