简体   繁体   中英

show page when loaded

I've tried multiple solutions, and nothing works for me. I tried this :

<script type="text/javascript">
$('body').hide();
$(document).ready(function() {
    $('body').show();
});
</script>

And with :

$(window).load(function() {.

The page loads as if it was not there.

Does someone have a code that works for real?

Patrick

can add a script tag in head that will create a style tag to hide body with css. Using script to create style tag means hiding body with default css won't affect user if js disabled

<script>
/* place in head tag so it fires before body is present*/
document.write('<style>body{display:none}</style>')

</script>

Then use jQuery to show within ready handler.

If problem is related to needing images loaded, there are many many posts on here to create image preloading script you could use to show body once all images loaded

i think u mean like that

   <script>  document.write('<style>body{display:none}</style>') </script>  // in head tag
       <script type="text/javascript">

      $(window).load(function() {
   $('body').show();
  });
     </script>

Why can't you set display:none in the body in the first place:

<body style="display:none;">

and then in the script tag you'll show it:

<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    </head>
    <body style="display:none;">
        <p>Text</p>
        <script type="text/javascript">
        $(document).ready(function(){$('body').show();});
        </script>
    </body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM