如何让浏览器等待显示页面,直到它完全加载? [英] How can I make the browser wait to display the page until it's fully loaded?

查看:735
本文介绍了如何让浏览器等待显示页面,直到它完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我讨厌如何实际查看网页载入。我认为等待页面完全加载并准备显示,包括所有脚本和图像,然后让浏览器显示它,这将是更有吸引力。因此,我有两个问题...


  1. 我该如何做?

  2. 一个总的noob到web开发,但这是常见的做法吗?

    >解决方案

    这是一个非常糟糕的主意,给出的所有原因,更多。也就是说,这里是如何使用 jQuery

     < body> 
    < div id =msgstyle =font-size:largest;>
    <! - 你可以设置任何你想要的风格 - >
    载入中,请稍候...
    < / div>
    < div id =bodystyle =display:none;>
    <! - 其他 - >
    < / div>
    < script type =text / javascript>
    $(document).ready(function(){
    $('#body')。show();
    $('#msg')。hide b});
    < / script>
    < / body>

    如果用户禁用JavaScript,则他们从不会看到该页面。如果页面从未完成加载,则他们从不会看到该页面。如果网页加载时间过长,他们可能会假设出现了问题,只是到其他地方,而不是*请稍候... * ing。


    I hate how you can actually see webpages load. I think it'd be much more appealing to wait until the page is fully loaded and ready to be displayed, including all scripts and images, and then have the browser display it. So I have two questions...

    1. How can I do this?
    2. I'm a total noob to web development, but is this common practice? If not, why?

    Thanks in advance for your wisdom!

    解决方案

    This is a very bad idea for all of the reasons given, and more. That said, here's how you do it using jQuery:

    <body>
    <div id="msg" style="font-size:largest;">
    <!-- you can set whatever style you want on this -->
    Loading, please wait...
    </div>
    <div id="body" style="display:none;">
    <!-- everything else -->
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#body').show();
        $('#msg').hide();
    });
    </script>
    </body>
    

    If the user has JavaScript disabled, they never see the page. If the page never finishes loading, they never see the page. If the page takes too long to load, they may assume something went wrong and just go elsewhere instead of *please wait...*ing.

    这篇关于如何让浏览器等待显示页面,直到它完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆