473,659 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1324
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.getEle mentById('extra Text').innerHTM L="for all good men"
}

var timer=window.se tTimeout('addTe xt()',5000)

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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript 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
3595
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 designed my "Do" loop to wait for each data set coming in at intervals of about 1/2 a second from the microprocessor. When I comment the following lines: bufferVar = ""
1
1767
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 ------------------- #include "C:\SystemC\systemc-2.0.1\src\systemc.h" #include "stimulus.h" #include "display.h" #include "fir.h"
1
1872
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 callback(System.Net.Sockets.OverlappedAsyncResult::CompletionPortCallback).T his exception occurs when our control is embedded within an IE web page. A connection is established after calling a web service, it keeps opened for a period of time(observd by using netstat), it seems that...
1
3077
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 use? If it has changed, what is the new endpoint url?
13
3915
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 ajax request to grab the content. Vice versa for right arrow key. Problem: the problem is when you multi-tap the arrow key a few times consecutively (4/5 of my testers do that to quickly get to the specific date they want), the ajax request call...
6
6379
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 information is a timestamp of the program in datetime format, which has it's own clock.
0
863
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./connect to remote SQL Server DB to manage message information among all people connected on PC1 and 2./upload upon request files on remote PC2. Now the connection remote PC1 and remote PC2 manage their communication with all client pc...
1
1781
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 pages DOM, there appears to be a conflict and/or race condition that pretty much locks the browser down for several minutes until one of the requests times out. A huge red flag stands out to me from the XHR object documentation...
10
1702
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> #include <string.h> #include <conio.h> #include <fcntl.h> #include <io.h>
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8747
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.