【问题标题】:Stop loading site to display a message停止加载站点以显示消息
【发布时间】:2025-12-11 14:25:01
【问题描述】:

我想在访问者进入网站之前向他们显示一条消息,然后允许他们使用按钮继续访问主网站。我也不想移动主要站点的位置。

与此类似:

<script>
    function continue() { /* function to continue loading site */ }
</script>

<p>This is a message. <button onclick="continue();">I agree</button></p>

<script>
    //stop loading what's below when someone enters the site, and display only the message
</script>

<html>
<body>
    <p>This is my main site with a lot of content.</p>
</body>
</html>

我不能只覆盖主站点,我不希望它的任何功能在访问者阅读消息时运行。

谁能指出我正确的方向?

【问题讨论】:

  • 您最有效的选择是覆盖页面并使用按钮淡出 div 以显示其余内容。具体是什么不允许您这样做?

标签: javascript php jquery html dom


【解决方案1】:

你不能停止通过 JS 加载页面。在某些情况下,JS 可以停止渲染页面。但它仍然可以被机器/show-source 读取。

如果你不想要封面网站,你可以通过style="display:none"隐藏一些元素。

如果页面必须是机器无法读取的,您必须在服务器端实现这一点:

<?php 
session_start(); 
if(!empty($_POST['policy'])) $_SESSION['accepted_policy'] = true; 
if(empty($_SESSION['accepted_policy'])) { 
?><form action="?" method="post"> 
<input type="checkbox" value="1" name="policy"> I've accepted ...<br /> 
<input type="submit" > </form>
<?php die(); 
} ?>
normal page

如果你不想在continue() 之前执行任何 JS,你可以从这个函数中运行它而不是 $.ready()

【讨论】:

    【解决方案2】:

    只需显示一个覆盖整个页面的大号div

    <html>
    <head>
    <style>
        .message{
         position: fixed;
         top: 0;
         bottom:0;
         left: 0;
         right: 0;
         z-index: 1000;
         background-color: grey;
        }
        </style>
        </head>
        <body>
        <div class="message" id="message">
        <!-- message -->
        Message<br/>
        <button onClick="document.getElementById('message').style.display='none';">
        Continue to Site
        </button>
        </div>
        <div class="content">
        <!-- Main content -->
        Main content
        </div>
        </body>
     </html>

    【讨论】:

    • 是的,不,正如我所说,我不想那样做。不过还是谢谢。
    • @JimmyVidzem 我发布了另一个可能适合您需求的答案。
    【解决方案3】:

    使用window.stop() 阻止窗口进一步加载。但是,这在 Internet Explorer 或 Microsoft Edge 中不起作用。

    <html>
    <head>
    </head>
    <body>
    Content that will be shown
    <script>
    window.stop();
    </script>
    Content that will not be shown
    </body>
    </html>

    【讨论】:

      最近更新 更多