FAQ Topic - How do I make a 10 second delay?

F

FAQ server

-----------------------------------------------------------------------
FAQ Topic - How do I make a 10 second delay?
-----------------------------------------------------------------------

There is no built-in way to pause execution in javascript such
as a sleep function, but hosts usually provide a method of some
form. Web browsers are designed for event driven programming and
only provide the « setTimeout » and « setInterval » functions
to facilitate timed delays. The delay before calling Snork will
generally exceed the second parameter to « setTimeout » and « setInterval »
due to implementation differences among browsers.

To call the function « Snork() », approx 10 seconds
after the function « Moomin() », you would do this:

Moomin()
setTimeout('Snork()',10000)

Script execution is not stopped, and adding « Snufkin() » after the
setTimeout line would immediately execute the function « Snufkin() »
before « Snork() »

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.

Other (less event driven) hosts have different wait functions,
such as « WScript.Sleep() » in the Windows Script Host.

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/setTimeout.asp

http://docs.sun.com/source/816-6408-10/window.htm#1203758

http://en.wikipedia.org/wiki/Event-driven_programming


===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.
 
E

Evertjan.

FAQ server wrote on 26 feb 2007 in comp.lang.javascript:

[..]
To call the function ® Snork() ¯, approx 10 seconds
after the function ® Moomin() ¯, you would do this:

Moomin()
setTimeout('Snork()',10000)

Script execution is not stopped, and adding ® Snufkin() ¯ after the
setTimeout line would immediately execute the function ® Snufkin() ¯
before ® Snork() ¯
[..]

This is right and also very amusing,
but the FAQ is not only for readers that
are fluent in English idiom and dialect.

The meaning of the ® and the ¯ escapes me,
but perhaps these are special characters
not understood by my reader.
Better avoid such characters.

"approx". Abbr. need a period,
but are better avoided in a FAQ.

Better, I hope:

================
To call the function B(), approximately 10 seconds
after the function A(), you would do this:

A();
setTimeout('B()',10000);

Script execution is not stopped, and adding C() after the
setTimeout() line would immediately
execute that function C() right after A() is finished and
10 seconds before B() starts executing.
=================
 
B

Bart Van der Donck

Evertjan. said:
FAQ server wrote on 26 feb 2007 in comp.lang.javascript:
Script execution is not stopped, and adding ® Snufkin()
¯ after the setTimeout line would immediately execute
the function ® Snufkin() ¯ before ® Snork() ¯

[..]
The meaning of the ® and the ¯ escapes me,
but perhaps these are special characters
not understood by my reader.

A news reader that doesn't understand ISO-8859-1 is no good. Those two
characters are:

U+00AB = in HTML &-#-171; or &-laquo;
U+00BB = in HTML &-#-187; or &-raquo;

(I'm adding Mini in order to make sure that no usenet client encodes
them)

Your reader is probably seeing them as CP437 or CP850:

http://en.wikipedia.org/wiki/IBM437
http://en.wikipedia.org/wiki/IBM850

In those tables, U+00AB in ISO-8859-1 (&-#-171;) corresponds to U+00AE
in the IBM sets, which corresponds in ISO-8859-1 to &-#-174; (&-
reg;).

Same for U+00BB which displays &-#-187; under ISO-8859-1 and &-#-175;
under CP437/CP850.

See comparison table on:
http://en.wikipedia.org/wiki/Western_Latin_character_sets_(computing)
 
V

VK

Evertjan. said:
FAQ server wrote on 26 feb 2007 in comp.lang.javascript:
[..]
The meaning of the ® and the ¯ escapes me,
but perhaps these are special characters
not understood by my reader.

A news reader that doesn't understand ISO-8859-1 is no good.

Windows XP SP2, Firefox 2.0.0.2 on Google Groups displays the same
broken text with trademark(?) and overline(?) signs instead of smart
quotes.
I guess the problem is again with jibbering.com server which seems
like to explore dark corners of HTTP :) The reported encoding is
UTF-8, so I guess it sends ISO-8859-1 encoded text with UTF-8 content-
type which is not suggested unless in QA labs.

I know that you are not on FAQ posting anymore but for anyone who
takes it over: it was a highly risky idea IMO to use smart quotes of
any kind in posting. There is no secure way to use them on the Web:
more exactly there are _several_ secure ways to do so - which
regularly means "don't use it for universal accessibility".
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
================
To call the function B(), approximately 10 seconds
after the function A(), you would do this:

A();
setTimeout('B()',10000);

Script execution is not stopped, and adding C() after the
setTimeout() line would immediately
execute that function C() right after A() is finished and
10 seconds before B() starts executing.
=================

AIUI, there is no need to put a function in the string where B() is;
it's reasonable to show one, but not to imply no alternative.

I tested : setTimeout("F.X0.value++", 2000) executed in js-
quick.htm showed nothing immediately, but changed a control after 2
seconds.

================
To perform the code represented by B() about 10 seconds
after executing the statement AAA, you could do this:

AAA ;
XXX = setTimeout("B()", 10000) // XXX can be used to clear the timeout
CCC ;

Script execution is not stopped be setTimeout or setInterval,
so statement CCC will be performed without delay.

For a repeated delay, one can use setInterval or put a call to
setTimeout within the function B.
=================


AIUI, in later browsers, setTimeout(B, 10000) works - yes,
function A() { xx } ; setTimeout(A, 1000) so that could be mentioned
too. But the string form is more capable.
 
G

Gertjan Klein

Bart said:
A news reader that doesn't understand ISO-8859-1 is no good.

The headers in the FAQ posting don't specify any encoding at all. If
special characters (i.e., outside ASCII) are to be used, an encoding
should be specified. (FWIW, Agent, my newsreader, displays these two
characters as registered trademark and overline as well.)

Gertjan.
 
B

Bart Van der Donck

Gertjan said:
The headers in the FAQ posting don't specify any encoding at all.

Well, this line is meant to set the encoding:

Content-Type: text/plain; charset="iso-8859-1"

And the following is just to make sure we're not in 7bit (ASCII):

Content-Transfer-Encoding: 8bit

Wrong ?
If special characters (i.e., outside ASCII) are to be
used, an encoding should be specified. (FWIW, Agent, my
newsreader, displays these two characters as registered
trademark and overline as well.)

Limiting a post to ASCII is always safe, yes. I'm starting to think
that Agent maybe uses another header besides Content-Type ?
 
B

Bart Van der Donck

VK said:
Evertjan. said:
FAQ server wrote on 26 feb 2007 in comp.lang.javascript:
Script execution is not stopped, and adding ® Snufkin()
¯ after the setTimeout line would immediately execute
the function ® Snufkin() ¯ before ® Snork() ¯
[..]
The meaning of the ® and the ¯ escapes me,
but perhaps these are special characters
not understood by my reader.
A news reader that doesn't understand ISO-8859-1 is no good.

Windows XP SP2, Firefox 2.0.0.2 on Google Groups displays the same
broken text with trademark(?) and overline(?) signs instead of smart
quotes.

Hm, XP SP2 FF 1.0.4. doesn't appear to show this problem here.
I guess the problem is again with jibbering.com server which seems
like to explore dark corners of HTTP :) The reported encoding is
UTF-8, so I guess it sends ISO-8859-1 encoded text with UTF-8 content-
type which is not suggested unless in QA labs.

I don't think it has anything to do with jibbering.com - it's about
how I format the message and which headers are used. The 2 symbols in
question are added at my side.

Do you mean by "reported encoding" the Google-page's charset in
Firefox ? All I can say is that the FAQ-postings are meant to be read
in ISO-8859-1. I don't know what a website further might do with it.
As far as I'm concerned, I'm not doing anything with UTF8 - and it
should really stay that way, if ISO-8859-1 already causes trouble :)

Here is an interesting link about charsets on Usenet:
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/9bc07b1d12e7a1df
I know that you are not on FAQ posting anymore but for anyone who
takes it over: it was a highly risky idea IMO to use smart quotes of
any kind in posting. There is no secure way to use them on the Web:
more exactly there are _several_ secure ways to do so - which
regularly means "don't use it for universal accessibility".

The "risk" is that I'm leaving ASCII, which *should* be possible in
2007 :)
 
R

Richard Cornford

Well, this line is meant to set the encoding:

Content-Type: text/plain; charset="iso-8859-1"

And the following is just to make sure we're not in 7bit (ASCII):

Content-Transfer-Encoding: 8bit

Wrong ?
<snip>

My news server receives those headers. However, (speculating) it may
be possible that there is an issue with the headers not being
propagated properly with the message, if some are not seeing them. In
that case the fault would probably be nearer to the individuals not
seeing the headers than the source of the messages.

Richard.
 
B

Bart Van der Donck

Richard said:
My news server receives those headers. However, (speculating)
it may be possible that there is an issue with the headers not
being propagated properly with the message, if some are not
seeing them.

Possibly. I am open for suggestions; AFAIK the headers should be
correct according to the standards.

In any case, I am choosing for maximum accessibility. I changed both
« (U+00AB) and » (U+00BB) to ` (U+0060) which is ASCII-safe.

The robot should be able to handle input up to ISO-8859-1 from the XML-
feed. But I would suggest that the FAQ itself would remain ASCII only
then (as it's now). And index.xml also not saved in an unicoded
encoding (as it's now, but I mention it anyway). This way is the
safest one and should work for any reader.
 
R

Randy Webb

Richard Cornford said the following on 2/27/2007 5:58 AM:
<snip>

My news server receives those headers. However, (speculating) it may
be possible that there is an issue with the headers not being
propagated properly with the message, if some are not seeing them. In
that case the fault would probably be nearer to the individuals not
seeing the headers than the source of the messages.

The content-type header shown to me by Thunderbird is:

Content-Type: text/plain; charset="iso-8859-1"

Yet I still see the Trademark and upperscore.
 
B

Bart Van der Donck

Randy said:
[...]
The content-type header shown to me by Thunderbird is:

Content-Type: text/plain; charset="iso-8859-1"

Yet I still see the Trademark and upperscore.

Think I understand it now. It looks like setting it to =AB resp. =BB
in the source should solve the problem; the decoding only seems to
take place from =XX to the corresponding character in ISO-8859-1.

Randy, VK, Evertjan (or anyone else who has the same problem), could
you confirm whether the following displays correctly ?

« Snork »

thanks
 
G

Gertjan Klein

Bart said:
Well, this line is meant to set the encoding:

Content-Type: text/plain; charset="iso-8859-1"

And the following is just to make sure we're not in 7bit (ASCII):

Content-Transfer-Encoding: 8bit

Wrong ?

No. I was looking at the wrong posting, my apologies. I don't have this
particular FAQ post anymore, so I can't check how it displays in Agent.
The message headers I looked in were from Evertjan's *response* to the
FAQ post, and those didn't specify an encoding, which prompted my reply.
Limiting a post to ASCII is always safe, yes. I'm starting to think
that Agent maybe uses another header besides Content-Type ?

I could not find any header in Evertjan's post related to encoding, so
all Agent can do is guess or fall back to some hardcoded default.

Gertjan.
 
G

Gertjan Klein

Bart said:
A news reader that doesn't understand ISO-8859-1 is no good. Those two
characters are:

U+00AB = in HTML &-#-171; or &-laquo;
U+00BB = in HTML &-#-187; or &-raquo;

Interestingly, in Evertjan's response to the FAQ posting these two
characters were recoded:

AB (in FAQ server post) -> AE (in Evertjan's reply)
BB (in FAQ server post) -> AF (in Evertjan's reply)

It looks like this is a problem with his newsreader. In reference to my
other recent post in this thread: I managed to retrieve the original FAQ
server posting, and it displays properly in Agent.

Gertjan.
 
E

Evertjan.

Gertjan Klein wrote on 27 feb 2007 in comp.lang.javascript:
Interestingly, in Evertjan's response to the FAQ posting these two
characters were recoded:

AB (in FAQ server post) -> AE (in Evertjan's reply)
BB (in FAQ server post) -> AF (in Evertjan's reply)

It looks like this is a problem with his newsreader. In reference to my
other recent post in this thread: I managed to retrieve the original FAQ
server posting, and it displays properly in Agent.

Gertjan.

No you are wrong.

Whatever my newsreader returns,
is not neccessarily what it shows while reading.

But that is not the point!

Javascript FAQ has no need for those characters that are encoded a miriad
of different ways. Plain extended ascii is capable enough.

btw, shall we go on in Dutch,
or are others still following this "draad"?

[Only joking, Randy]
 
B

Bart Van der Donck

Evertjan. said:
Javascript FAQ has no need for those characters that
are encoded a miriad of different ways. Plain extended
ascii is capable enough.

"Plain extended ascii" ? I wish that would exist :)

ASCII was okay for English on early computers. Then programmers found
out that it was too narrow. An eight bit was added to double the
characters (2^7 to 2^8). The idea was that the new code points could
be used to display any character range depending on the table set, see
e.g. Russian, Turkish, etc. or even the western variants:
Windows-1252, ISO-8859-1/15, Mac OS Roman, IBM437/850, ... Also the
"upper ASCII" that you mention (didn't know that existed) belongs to
this category. At that time it seemed to be a suitable solution; just
define a char table you have 128 chars to use to represent anything.
With Unicode, this whole view changed.

As ISO-8859-1 became the default set for HTTP, it's a pretty safe shot
that every program of the last 15 years should support it.
 
R

Randy Webb

Bart Van der Donck said the following on 2/27/2007 11:03 AM:
Randy said:
[...]
The content-type header shown to me by Thunderbird is:

Content-Type: text/plain; charset="iso-8859-1"

Yet I still see the Trademark and upperscore.

Think I understand it now. It looks like setting it to =AB resp. =BB
in the source should solve the problem; the decoding only seems to
take place from =XX to the corresponding character in ISO-8859-1.

Randy, VK, Evertjan (or anyone else who has the same problem), could
you confirm whether the following displays correctly ?

« Snork »

Yes it does, for me.
 
R

Randy Webb

Evertjan. said the following on 2/27/2007 11:53 AM:

btw, shall we go on in Dutch,
or are others still following this "draad"?

[Only joking, Randy]

That is why I laughed about it :)
 
G

Gertjan Klein

Evertjan. said:
Gertjan Klein wrote on 27 feb 2007 in comp.lang.javascript:

No you are wrong.

I might be, but I wouldn't dismiss my statement so quickly.
Whatever my newsreader returns,
is not neccessarily what it shows while reading.

I didn't claim it was. I compared the FAQ posting, containing AB and BB,
to your response to that post, which quoted these characters. In your
post (at least my copy of it) the quoted characters were changed to AE
and AF. (I checked that by saving both posts and viewing them binary.)
Something must have changed them. It is unlikely that Agent (my
newsreader) did, as it has no reason to. It is possible, but also
unlikely, that some news server along the way changed the characters. To
me it seems most likely that your client posted what it displayed to you
(although I have no idea why it would do that).

Gertjan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top