How to display progress bar until whole aspx page is load?

核能气质少年 提交于 2019-12-23 03:32:33

问题


I have a master page Root.master and a page default.aspx . I want to display progress bar until whole default.aspx page is loaded .

I tried following code:-

<html>
<head><title>xx</title>
</head>
<body style="visibility:hidden;" onload="function(){document.body.visibility='visible'}">
<img src="xxxx.gif" style="visibility:visible !important">

</body>
</html>

But problem is that I do not have body on default.aspx , it is on root.master , if we put it on root.master, it apply all pages which inherit from root.master . So there is another for it .

Please suggest me usable link or samples.


回答1:


in your sample if you are using jQuery, you can use following re-factoring to your code

 $(document).load(function(){
     $('body').css('visibility','visible');
 }



回答2:


You can add a reference to jQuery and then do a little code something like:

<html>
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      $(document).ready(){  // Wait until the page has finished loading
        if ($(".ProgressBar"))  // Detect the element with class ProgressBar
        {
          $(".ProgressBar").hide();  // If found, set it to be display:none;
        }
      }
    </script>
  </head>
  <body>
    <div class="ProgressBar">
      <img src="Whatever.gif" alt="Please wait..." />
    </div>
  </body>
</html>

Also doable without jQuery but it's just so much easier to use it ;)

That way the progress bar gif loads, and once the page is done it is set to invisible.

I hope that might help! Good luck.




回答3:


You don't mention any libraries, so here is a pure js solution: http://jsfiddle.net/TTU7v/
The idea is to put the script as close to the opening body tag (but after it!) as possible:

<script type="text/javascript">
var body = document.getElementsByTagName("body")[0];
body.style.visibility = "hidden";
window.onload = function(){body.style.visibility = "visible";};
</script>


来源:https://stackoverflow.com/questions/8612769/how-to-display-progress-bar-until-whole-aspx-page-is-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!