找回密码
 立即注册
搜索
查看: 269|回复: 2

如何让下载慢的网页部分出现进度条?

[复制链接]

36

主题

3824

回帖

2761

积分

论坛元老

问佛

积分
2761
发表于 2004-8-9 18:27:59 | 显示全部楼层 |阅读模式
我的网站首页调用了其它网站的论坛新帖列表,有时候网络故障,那个论坛打不开,结果我的页面要很长的时间才能渲染出来。

我如何可以让那个新帖列表处出现一个进度条,先加载本地网页,全部页面显示完成后再调用那个论坛的新帖。

求高手帮助。

3

主题

9

回帖

16

积分

新手上路

积分
16
发表于 2004-8-11 10:52:11 | 显示全部楼层

给你一个asp.net的例子吧

下面就是具体的实现过程:

新建项目,名字为WebPortal,在项目类型中选择Visual C#项目或者Visual Basic项目都可;
在模板类型中选择ASP.NET Web应用程序;
位置里输入:http://localhost/WebPortal;
添加新项:名字为ShowProgress的Web窗体。
在您的Web窗体ShowProgress.aspx上添加任何其他的Web服务器控件。
在ShowProgress.aspx上单击右键,点“查看代码”,在最上面输入:
Visual C# .NET代码
using System.Threading;

Visual Basic .NET代码
Imports System.Threading

在Page_Load事件里输入: Visual C# .NET代码
Response.Write("<div id='mydiv' >");
Response.Write("_");
Response.Write("</div>");
Response.Write("<script>mydiv.innerText = '';</script>");
Response.Write("<script language=javascript>;");
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()");
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ");
Response.Write("window.setInterval('ShowWait()',1000);}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';");
Response.Write("window.clearInterval();}");
Response.Write("StartShowWait();</script>");
Response.Flush();
Thread.Sleep(10000);

Visual Basic .NET代码
Response.Write("<div id='mydiv' >")
Response.Write("_")
Response.Write("</div>")
Response.Write("<script>mydiv.innerText = '';</script>")
Response.Write("<script language=javascript>;")
Response.Write("var dots = 0;var dotmax = 10;function ShowWait()")
Response.Write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;")
Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText =  output;}")
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ")
Response.Write("window.setInterval('ShowWait()',1000);}")
Response.Write("function HideWait(){mydiv.style.visibility='hidden';")
Response.Write("window.clearInterval();}")
Response.Write("StartShowWait();</script>")
Response.Flush()
Thread.Sleep(10000)

在ShowProgress.aspx窗体的html的中输入:
<script>
HideWait();
</script>

点在浏览器中查看即可。
回复

使用道具 举报

36

主题

3824

回帖

2761

积分

论坛元老

问佛

积分
2761
 楼主| 发表于 2004-8-11 14:55:12 | 显示全部楼层
我找到方法了,其实很简单,关键在于浏览器的渲染方式是自上而下。

与小胡子的方法差不多,用js实现

<html>
<body>
<div id="showNews">载入中,请稍候...(这里可以用一个进度条表示)</div>
.......

页面其它内容
.......
.......

<div id="newsLoading" style="display:none">
用隐藏层放入加载慢的内容
<script src="别的网站调用地址"></script>
</div>
<script>
//把加载完成的内容显示出来
showNews.innerHTML=newsLoading.innerHTML;
</script>
<body>
</html>

如此一来就可以加快页面的显示了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|海浩社区

GMT+8, 2025-9-19 22:31 , Processed in 0.073227 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表