Webpage programming question.
Discussion
'Ello,
I have just about worked out how to auto refresh after 30 seconds but what I would like a screen that displays:
This could take a while
Please wait.
and a series of dots that crawl across the screen, then after 30 or 10 or whatever seconds refreshes the page.
My programming skills in HTML thingy are about 5%
Ta.
I have just about worked out how to auto refresh after 30 seconds but what I would like a screen that displays:
This could take a while
=================
Please wait.
and a series of dots that crawl across the screen, then after 30 or 10 or whatever seconds refreshes the page.
My programming skills in HTML thingy are about 5%
Ta.
Edited by Morningside on Friday 15th June 16:48
You do this with Javascript to manipulate the DOM.
You need to look in to the JavaScript function setInterval whiich allows you to define a function that gets called at regular intervals.
Here is a basic example...
The HTML renders a simple 4 x 4 series of blocks in the center of screen.
When the JavaScript block is hit by the browser the setInterval method is invoked and set to invoke the startProgress() method every 250ms - note that the id returned from setInterval is saved so that it can be used in the call to clearInterval
There are 2 JavaScript blocks the first is the one that starts up the progress display and ther second is the one that finishes it.
Be warned...The example is based on ASP code that has been tested only on IE6 and 7. It relies on you using the Response.Buffer = false statement (otherwise the code won't reach the browser until the whole page is rendered) and by definition requires that JavaScript is enabled.
<span id="progressSection">
<div class=ProgressBox>
<!--This the progress area-->
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td valign=middle align=center>
<!--Progress matrix-->
<table width=120 height=120 cellpadding=0 cellspacing=2>
<tr style="height: 30px">
<td id=p1 width=30 Class=ThisProgress> </td>
<td id=p2 width=30 Class=Progress> </td>
<td id=p3 width=30 Class=Progress> </td>
<td id=p4 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p12 width=30 Class=LastProgress> </td>
<td id=p13 width=30 Class=Progress> </td>
<td id=p14 width=30 Class=Progress> </td>
<td id=p5 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p11 width=30 Class=Progress> </td>
<td id=p16 width=30 Class=Progress> </td>
<td id=p15 width=30 Class=Progress> </td>
<td id=p6 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p10 width=30 Class=Progress> </td>
<td id=p9 width=30 Class=Progress> </td>
<td id=p8 width=30 Class=Progress> </td>
<td id=p7 width=30 Class=Progress> </td>
</tr>
</table>
<!--End progress matrix-->
<td>
</tr>
</table>
</div>
</span>
<script language="JavaScript">
//Progress handling code
var progressPath = [1,2,3,4,5,6,7,8,9,10,11,12];
var pathPosition = 0;
var intervalId;
intervalId = setInterval('startProgress()', 250);
function startProgress()
{
var thisPathElement = document.all('p' + progressPath[pathPosition]);
var lastPathElement = null;
var priorPathElement = null;
var centerElement = null;
if ((pathPosition - 2) >= 0)
{
priorPathElement = document.all('p' + progressPath[pathPosition - 2]);
}
if ((pathPosition - 1) >= 0)
{
lastPathElement = document.all('p' + progressPath[pathPosition - 1]);
}
thisPathElement.className = 'ThisProgress';
if (lastPathElement != null) lastPathElement.className = 'LastProgress';
if (priorPathElement != null) priorPathElement.className = 'Progress';
switch (pathPosition)
{
case 0:
document.all('p' + progressPath[progressPath.length - 1]).className = 'LastProgress';
document.all('p' + progressPath[progressPath.length - 2]).className = 'Progress';
centerElement = document.all('p13');
triState(centerElement);
break;
case 1:
document.all('p' + progressPath[progressPath.length - 1]).className = 'Progress';
break;
case 3:
centerElement = document.all('p14');
triState(centerElement);
break;
case 6:
centerElement = document.all('p15');
triState(centerElement);
break;
case 9:
centerElement = document.all('p16');
triState(centerElement);
break;
}
pathPosition += 1;
if (pathPosition >= progressPath.length) pathPosition = 0;
}
function triState(aElement)
{
switch (aElement.className)
{
case 'Progress':
aElement.className = 'LastProgress';
break;
case 'LastProgress':
aElement.className = 'ThisProgress';
break;
case 'ThisProgress':
aElement.className = 'Progress';
break;
}
}
function stopProgress()
{
clearInterval(intervalId);
}
</script>
Do your long running task/s here....
<script language="JavaScript">
stopProgress();
document.all('progressSection').style.display = 'none';
</script>
You need to look in to the JavaScript function setInterval whiich allows you to define a function that gets called at regular intervals.
Here is a basic example...
The HTML renders a simple 4 x 4 series of blocks in the center of screen.
When the JavaScript block is hit by the browser the setInterval method is invoked and set to invoke the startProgress() method every 250ms - note that the id returned from setInterval is saved so that it can be used in the call to clearInterval
There are 2 JavaScript blocks the first is the one that starts up the progress display and ther second is the one that finishes it.
Be warned...The example is based on ASP code that has been tested only on IE6 and 7. It relies on you using the Response.Buffer = false statement (otherwise the code won't reach the browser until the whole page is rendered) and by definition requires that JavaScript is enabled.
<span id="progressSection">
<div class=ProgressBox>
<!--This the progress area-->
<table width=100% cellpadding=0 cellspacing=0>
<tr>
<td valign=middle align=center>
<!--Progress matrix-->
<table width=120 height=120 cellpadding=0 cellspacing=2>
<tr style="height: 30px">
<td id=p1 width=30 Class=ThisProgress> </td>
<td id=p2 width=30 Class=Progress> </td>
<td id=p3 width=30 Class=Progress> </td>
<td id=p4 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p12 width=30 Class=LastProgress> </td>
<td id=p13 width=30 Class=Progress> </td>
<td id=p14 width=30 Class=Progress> </td>
<td id=p5 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p11 width=30 Class=Progress> </td>
<td id=p16 width=30 Class=Progress> </td>
<td id=p15 width=30 Class=Progress> </td>
<td id=p6 width=30 Class=Progress> </td>
</tr>
<tr style="height: 30px">
<td id=p10 width=30 Class=Progress> </td>
<td id=p9 width=30 Class=Progress> </td>
<td id=p8 width=30 Class=Progress> </td>
<td id=p7 width=30 Class=Progress> </td>
</tr>
</table>
<!--End progress matrix-->
<td>
</tr>
</table>
</div>
</span>
<script language="JavaScript">
//Progress handling code
var progressPath = [1,2,3,4,5,6,7,8,9,10,11,12];
var pathPosition = 0;
var intervalId;
intervalId = setInterval('startProgress()', 250);
function startProgress()
{
var thisPathElement = document.all('p' + progressPath[pathPosition]);
var lastPathElement = null;
var priorPathElement = null;
var centerElement = null;
if ((pathPosition - 2) >= 0)
{
priorPathElement = document.all('p' + progressPath[pathPosition - 2]);
}
if ((pathPosition - 1) >= 0)
{
lastPathElement = document.all('p' + progressPath[pathPosition - 1]);
}
thisPathElement.className = 'ThisProgress';
if (lastPathElement != null) lastPathElement.className = 'LastProgress';
if (priorPathElement != null) priorPathElement.className = 'Progress';
switch (pathPosition)
{
case 0:
document.all('p' + progressPath[progressPath.length - 1]).className = 'LastProgress';
document.all('p' + progressPath[progressPath.length - 2]).className = 'Progress';
centerElement = document.all('p13');
triState(centerElement);
break;
case 1:
document.all('p' + progressPath[progressPath.length - 1]).className = 'Progress';
break;
case 3:
centerElement = document.all('p14');
triState(centerElement);
break;
case 6:
centerElement = document.all('p15');
triState(centerElement);
break;
case 9:
centerElement = document.all('p16');
triState(centerElement);
break;
}
pathPosition += 1;
if (pathPosition >= progressPath.length) pathPosition = 0;
}
function triState(aElement)
{
switch (aElement.className)
{
case 'Progress':
aElement.className = 'LastProgress';
break;
case 'LastProgress':
aElement.className = 'ThisProgress';
break;
case 'ThisProgress':
aElement.className = 'Progress';
break;
}
}
function stopProgress()
{
clearInterval(intervalId);
}
</script>
Do your long running task/s here....
<script language="JavaScript">
stopProgress();
document.all('progressSection').style.display = 'none';
</script>
Edited by GnuBee on Friday 15th June 08:40
At first glance you should be able to stick it anywhere between the <body></body> tags. An alternative and slightly prettier way of doing something like the line of dots might be to use an animated gif to show that something is happening in the background?
I'm not sure whether you've worked it out already, but you can do the page refresh thing by putting:
<meta http-equiv="refresh" content="30">
somewhere between the <head></head> tags - usually at the top.
I'm not sure whether you've worked it out already, but you can do the page refresh thing by putting:
<meta http-equiv="refresh" content="30">
somewhere between the <head></head> tags - usually at the top.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff



I would never work that out in a million years. Now next question (Mr Numpty time).