473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem getting a timed delay

I've read the FAQ about means of implementing a delay, but nothing
seems to work for me. My HTML page looks like this:

<html>
<head>
.... usual html stuff and then:
<script type="text/javascript">
function pause( milliseconds )
{
var date = new Date();
var curDate = null;
do
{ curDate = new Date(); }
while( curDate - date < milliseconds );
}
</script>
</head>

And then I do something like:
<body>
<p>
Now is the time
<script type="text/javascript">
pause( 5000 );
</script>
for all good men ...
</p>
</body>
</html>

My intention is to have "Now is the time" print followed by a 5-second
delay followed by "for all good men ..."

Sadly what actually happens is that the entire webpage delays for 5
seconds before loading and then "Now is the time for all good men ..."
prints as a unit. Can anyone tell me what I'm doing wrong before I go
insane? Many thanks for any and all help.

Feb 27 '07 #1
1 1311
whitesmith said the following on 2/27/2007 2:56 PM:
I've read the FAQ about means of implementing a delay, but nothing
seems to work for me.
If you read the FAQ about it then why didn't you implement the methods
in the FAQ? And, the FAQ also says the way you tried is a bad idea.

<quote>
Achieving delays through running a loop of some sort for a pre-defined
period is a bad strategy, as that will tend to put CPU use up to 100%
and inhibit whatever was supposed to be happening during the delay.
</quote>

Which is exactly the behavior you are getting.
My intention is to have "Now is the time" print followed by a 5-second
delay followed by "for all good men ..."
function addText(){
document.getElementById('extraText').innerHTML="fo r all good men"
}

var timer=window.setTimeout('addText()',5000)

<div>Now is the time</div>
<div id="extraText"></div>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sonoman | last post by:
Hello everyone: I am new to Visual Basic and I have a problem that I cannot put my finger on. I am working on a school project and I am getting some serial data from a microprocessor. I have...
1
by: David Li | last post by:
I am having a lot of problem with following code. To start with I have a working sets of code and the top level SystemC code looks like this: ----------working main.cpp start here...
1
by: VincentWong | last post by:
hi all, We're getting a security exception (An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll) on a asychronous...
1
by: mirandacascade | last post by:
Operating system: Win XP Is it possible that the endpoint url of: "http://66.28.98.121:9090/soap" that is provided for the SOAP example of calling GetQuote has changed or is no longer in...
13
by: alvinwoon | last post by:
URL: http://events.unl.edu/ Description: i coded a quick and dirty key navigation for the calendar. if you press left arrow on your keyboard, it will navigate to the previous date and fire an...
6
by: Matik | last post by:
Hi, I have a funny situation. Within: MSSQL 2000 SP3, everything below described is running on same PC. there is a program running, which sends information to two other programs. This...
0
by: harryben | last post by:
Hi Everyone, I tried to post this thread in microsoft public forum with no success. However, heres the situation, I ve been developping a WinForm Application in C#. This Application does 2 things...
1
by: Christoph Boget | last post by:
I'm experiencing a very odd problem and it's happening only in IE6. IE7, Safari, Opera and Firefox are all working properly. What's happening is that I'm using XHR request responses to update the...
10
by: biplab | last post by:
Sorry to bother again u people with the same code.....but another astonishing problem arising....please help me.... #include <stdio.h> #include <stdlib.h> #include <dos.h> #include <mem.h>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.