Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

1 view
Skip to first unread message

FAQ server

unread,
Feb 25, 2007, 7:00:01 PM2/25/07
to
-----------------------------------------------------------------------
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.

Evertjan.

unread,
Feb 26, 2007, 2:33:35 AM2/26/07
to
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.
=================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Bart Van der Donck

unread,
Feb 26, 2007, 4:14:37 AM2/26/07
to
"Evertjan." wrote:

> 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_%28computing%29

--
Bart

VK

unread,
Feb 26, 2007, 5:14:52 AM2/26/07
to
On Feb 26, 12:14 pm, "Bart Van der Donck" <b...@nijlen.com> wrote:
> "Evertjan." wrote:
> > 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.
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".

Gertjan Klein

unread,
Feb 26, 2007, 4:57:20 PM2/26/07
to
Bart Van der Donck wrote:

> "Evertjan." wrote:
>
>> 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.

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.

--
Gertjan Klein <gkl...@xs4all.nl>

Dr J R Stockton

unread,
Feb 26, 2007, 12:37:18 PM2/26/07
to
In comp.lang.javascript message <Xns98E35713...@194.109.133.242>
, Mon, 26 Feb 2007 07:33:35, Evertjan. <exjxw.ha...@interxnl.net>
posted:

>================
>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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Bart Van der Donck

unread,
Feb 27, 2007, 3:55:21 AM2/27/07
to
Gertjan Klein wrote:

> 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 ?

--
Bart

Bart Van der Donck

unread,
Feb 27, 2007, 4:15:37 AM2/27/07
to
VK wrote:

> On Feb 26, 12:14 pm, "Bart Van der Donck" <b...@nijlen.com> wrote:
>
> > "Evertjan." wrote:
> > > 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 :)

--
Bart

Richard Cornford

unread,
Feb 27, 2007, 5:58:38 AM2/27/07
to
On Feb 27, 8:55 am, "Bart Van der Donck" <b...@nijlen.com> wrote:
> Gertjan Klein wrote:
>> 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 ?
<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.

Bart Van der Donck

unread,
Feb 27, 2007, 7:16:32 AM2/27/07
to
Richard Cornford wrote:

> "Bart Van der Donck" <b...@nijlen.com> wrote:

>> 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
>

> 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.

--
Bart

Randy Webb

unread,
Feb 27, 2007, 10:44:57 AM2/27/07
to
Richard Cornford said the following on 2/27/2007 5:58 AM:

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.

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

Bart Van der Donck

unread,
Feb 27, 2007, 11:03:40 AM2/27/07
to
Randy Webb wrote:

> [...]


> 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

--
Bart

Gertjan Klein

unread,
Feb 27, 2007, 11:13:28 AM2/27/07
to
Bart Van der Donck wrote:

>Gertjan Klein wrote:
>
>> 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 ?

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.

Evertjan.

unread,
Feb 27, 2007, 11:25:29 AM2/27/07
to
Bart Van der Donck wrote on 27 feb 2007 in comp.lang.javascript:

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

Yes it shows the short form of:

<< Snork >>

[in Xnews]

Those are "upper" ascii >127 (hex 8F):

<http://ascii-table.com/img/table-apple.gif>

These are "real" or "lower" ascii (bit8=0):

<http://ascii-table.com/img/table.gif>

Gertjan Klein

unread,
Feb 27, 2007, 11:30:02 AM2/27/07
to
Bart Van der Donck wrote:

>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.

Evertjan.

unread,
Feb 27, 2007, 11:53:34 AM2/27/07
to

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]

Bart Van der Donck

unread,
Feb 27, 2007, 12:19:05 PM2/27/07
to
Evertjan. wrote:

> 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.

--
Bart

Randy Webb

unread,
Feb 27, 2007, 2:53:56 PM2/27/07
to
Bart Van der Donck said the following on 2/27/2007 11:03 AM:

Yes it does, for me.

Randy Webb

unread,
Feb 27, 2007, 2:55:39 PM2/27/07
to
Evertjan. said the following on 2/27/2007 11:53 AM:

<snip>

> btw, shall we go on in Dutch,
> or are others still following this "draad"?
>
> [Only joking, Randy]

That is why I laughed about it :-)

Gertjan Klein

unread,
Feb 28, 2007, 11:07:05 AM2/28/07
to
Evertjan. wrote:

>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)
>>

>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).

Evertjan.

unread,
Feb 28, 2007, 1:28:40 PM2/28/07
to

Well it does not [return as id displayed], due to a quirk in Xnews,
but even if it did, that would NOT mean that you, with another
newsreader, would see it as I saw it.

The coding, when not changed, will remain the same, don't you think?

==============

However, please do not skip my point, that that does not matter:
The FAQ should be written as plain as possible in flat text,
[or displayed on the web as html.]

Whenever the FAQ is posted on it's own NG, flat text is mandatory.

Bart Van der Donck

unread,
Feb 28, 2007, 2:20:20 PM2/28/07
to
Evertjan. wrote:

> [...]


> The FAQ should be written as plain as possible in flat text,
> [or displayed on the web as html.]
>
> Whenever the FAQ is posted on it's own NG, flat text is mandatory.

I have a feeling that the problem in question is due to an incorrect
transmission of 8bit-data somewhere along the route or at the reader.
While email and usenet traffic were traditionally transported in 7bit,
a header like:

Content-Transfer-Encoding: 8bit

should be supported too, see (the RFC is from 1994 already):

http://tools.ietf.org/html/rfc1652
http://en.wikipedia.org/wiki/8BITMIME

Alternatively,

Content-Transfer-Encoding: quoted-printable

together with =AB/=BB in stead of «/» could have been used too. And
that's where I was wrong in the other FAQ post of today. I set it as
8bit and then still used =AB/=BB, which then weren't decoded of
course.

http://en.wikipedia.org/wiki/Quoted-printable
http://en.wikipedia.org/wiki/MIME#Content-Transfer-Encoding

Anyway - as for the FAQ postings: ASCII it is :-) You have a good
point that this requires nothing from any reader or intermediate
server, so it guarantees maximum accessibility.

--
Bart

0 new messages