【问题标题】:How to insert page loading code on my aspx page?如何在我的 aspx 页面上插入页面加载代码?
【发布时间】:2011-03-15 08:57:32
【问题描述】:

我准备了一个 ASP.NET 网站。但它包含许多闪光控制。进入页面时,一些flash控件无法加载,但页面正在打开。所以flash部分显示不好。

为了解决这个问题,我想在aspx页面上添加一个页面加载代码。在页面完全加载之前,会显示图片或礼物。

请给我一个代码,但我不知道如何将代码添加到 aspx 页面,所以我也需要一些说明。

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    如果您只是想在加载时覆盖屏幕,那么这样的事情应该可以解决问题:

    <script type="text/javascript">
    (function()
    {   
      if (window.addEventListener)
      {
        window.addEventListener("load", hide_loading_screen, false);    
      }
      else
      {
        window.attachEvent("onload", hide_loading_screen);
      }
    })();
    
    function display_loading_screen()
    {
      document.getElementById("loading_screen").style.display = 'block';
    }
    
    function hide_loading_screen()
    {
      document.getElementById("loading_screen").style.display = 'none';
    }
    </script>
    
    <style type="text/css">
    #loading_screen
    {  
      display: none;
      position: absolute;
      left: 0px;
      top: 0px;
      height: 100%;
      width: 100%;
      background-color: black;
      color: white;  
      text-align: center;
      padding-top: 100px;
      z-index: 1000;
    }
    </style>
    
    </head>
    
    <body>
    
    <div id="loading_screen">
      <h1>Loading...</h1>
      <h3>Please Wait...</h3>
    </div>
    
    <script type="text/javascript">display_loading_screen();</script>
    
    </body>
    

    如果您愿意,可以将 loading_screen div 上的 CSS 更改为图像。

    如果您使用的是 jQuery,那么您可以将 window.addEventListener 替换为 $(document).ready() 处理程序。如果您不使用 jQuery,那么您可能应该是....

    【讨论】:

    • 你好,谢谢你的回复,我如何通过css将这个java脚本代码添加到aspx页面?请你告诉我指导方式,
    • 嗨。您不能使用 CSS 添加 JavaScript 代码。您可以直接将以上所有代码添加到页面中,也可以将其拆分并将 JavaScript 放入单独的外部 .js 文件中,将 CSS 放入单独的外部 .css 文件中。然后,您将使用通常的外部
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2012-04-10
    相关资源
    最近更新 更多