Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #9190 > unrolled thread
| Started by | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| First post | 2011-12-13 10:26 -0700 |
| Last post | 2011-12-15 14:34 -0700 |
| Articles | 20 on this page of 22 — 8 participants |
Back to article view | Back to comp.lang.javascript
Showing a 'Waiting ...' Message "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-13 10:26 -0700
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-13 12:17 -0800
Re: Showing a 'Waiting ...' Message "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-13 15:31 -0700
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-13 17:50 -0800
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-13 18:10 -0800
Re: Showing a 'Waiting ...' Message Martin Pearman <warwound@gmail.com> - 2011-12-13 23:07 -0800
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-14 10:46 -0800
Re: Showing a 'Waiting ...' Message Jake Jarvis <pig_in_shoes@yahoo.com> - 2011-12-14 21:18 +0100
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-14 13:30 -0800
Re: Showing a 'Waiting ...' Message "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-14 22:56 +0000
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-14 18:55 -0800
Re: Showing a 'Waiting ...' Message tony@mountifield.org (Tony Mountifield) - 2011-12-15 08:40 +0000
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-15 12:08 -0800
Re: Showing a 'Waiting ...' Message tony@mountifield.org (Tony Mountifield) - 2011-12-15 20:36 +0000
Re: Showing a 'Waiting ...' Message Gene Wirchenko <genew@ocis.net> - 2011-12-15 15:24 -0800
Re: Showing a 'Waiting ...' Message Scott Sauyet <scott.sauyet@gmail.com> - 2011-12-16 06:31 -0800
Re: Showing a 'Waiting ...' Message Dr J R Stockton <reply1150@merlyn.demon.co.uk> - 2011-12-16 21:17 +0000
Re: Showing a 'Waiting ...' Message "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-15 11:03 +0000
Re: Showing a 'Waiting ...' Message Dr J R Stockton <reply1150@merlyn.demon.co.uk> - 2011-12-15 20:42 +0000
Re: Showing a 'Waiting ...' Message Dr J R Stockton <reply1150@merlyn.demon.co.uk> - 2011-12-14 21:11 +0000
Re: Showing a 'Waiting ...' Message "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-14 16:54 -0700
Re: Showing a 'Waiting ...' Message "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-15 14:34 -0700
Page 1 of 2 [1] 2 Next page →
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2011-12-13 10:26 -0700 |
| Subject | Showing a 'Waiting ...' Message |
| Message-ID | <9kpg77Fu2fU1@mid.individual.net> |
Hi:
Because of some great help from Denis McMahon last March, I've been
showing / sorting big tables with no problem
The only problem I have is displaying a 'Waiting for Sort to Complete
...' message on the screen during the interval that sorting is taking place.
The 'Wait' Message *does* display if I follow it with an Alert()
message. Otherwise, it does *not* display.
Is there some other way to *force* this following function to display ??
// **** here is the 'wait' message function ****
function showwaitmsg() {
var el = document.getElementById("sorttext")
el.style.color="white";
el.style.background="red" ;
el.value = " Sorting ... " ; // in IE7 and also Chrome, this doesn't
display UNLESS you show an alert() message first
return ;
}
// **** end of wait message function ****
Thanks for any hints provided !
--
Mel Smith
[toc] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-13 12:17 -0800 |
| Message-ID | <8n5fe799liibkn298t5l4h82qjbler0j99@4ax.com> |
| In reply to | #9190 |
On Tue, 13 Dec 2011 10:26:34 -0700, "Mel Smith"
<med_cutout_syntel@aol.com> wrote:
> Because of some great help from Denis McMahon last March, I've been
>showing / sorting big tables with no problem
>
> The only problem I have is displaying a 'Waiting for Sort to Complete
>...' message on the screen during the interval that sorting is taking place.
>
> The 'Wait' Message *does* display if I follow it with an Alert()
>message. Otherwise, it does *not* display.
>
> Is there some other way to *force* this following function to display ??
You are not the only one to do battle with this. I am another. I
found in my searching that many people had this problem. I do not
have a for-sure answer, but for what it is worth...
In my case, it was a tictactoe program. I was not always getting
the display updated with the final plays before the win/lose alert()
was displayed.
>// **** here is the 'wait' message function ****
>function showwaitmsg() {
> var el = document.getElementById("sorttext")
> el.style.color="white";
> el.style.background="red" ;
> el.value = " Sorting ... " ; // in IE7 and also Chrome, this doesn't
>display UNLESS you show an alert() message first
> return ;
>}
>// **** end of wait message function ****
>
> Thanks for any hints provided !
In my case, I replaced the alert() with a setTimeout() to call
another function (consisting of the alert() I wanted) with a timeout
of 0 and then ended execution. It is important that execution end, or
the function specified in the setTimeout() will not execute.
I found that 0 worked just fine. I suspect that this allows the
screen update thread an opportunity to run.
In a related vein, I was trying to write something that would
show an update such as
1000 thingies somethingerised
2000 thingies somethingerised
3000 thingies somethingerised
I got something that worked reliably, but unfortunately, I threw out
my code. IIRC, my loop variable had to be global. I have tried to
recreate the code, but the following does not quite work. The
document.write() causes Looping() to become undefined! If I use an
alert() instead (which rather defeats the purpose), it works.
***** Start of Semi-Working Code *****
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>trytimeout.html</title>
<script type="text/javascript">
var i;
function LoopStart()
{
alert("{LoopStart()");
i=1;
setTimeout("Looping()",0);
}
function Looping()
{
alert("{Looping @i="+i);
DoSomething();
if (i%3==0)
document.writeln(i+" thingies somethingerised<br>"); //*****
This causes trouble.
i++;
if (i<=10)
{
alert("@Looping() <setTimeout() @i="+i);
setTimeout("Looping()",0);
alert("@Looping() >setTimeout() @i="+i);
}
}
function DoSomething()
{
for (var i=1; i<=1000; i++)
;
}
</script>
</head>
<body>
<script type="text/javascript">
LoopStart();
</script>
</body>
</html>
***** End of Semi-Working Code *****
The above is a semi-educated guess, and I would welcome
correction if there is a reliable, cross-platform way to do it.
Sincerely,
Gene Wirchenko
2
[toc] | [prev] | [next] | [standalone]
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Date | 2011-12-13 15:31 -0700 |
| Message-ID | <9kq22gFh0cU1@mid.individual.net> |
| In reply to | #9198 |
Gene:
Thanks for the code. I'll work on trying to implement it and let you
know.
-Mel Smith
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-13 17:50 -0800 |
| Message-ID | <d40ge7tnra6pusatipdsao37hb06c0vfq2@4ax.com> |
| In reply to | #9199 |
On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
<med_cutout_syntel@aol.com> wrote:
> Thanks for the code. I'll work on trying to implement it and let you
>know.
I am going to take another whack at it. I had it working.
HONEST! REALLY! I thought I had the issue dealt with and so could
toss the code.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-13 18:10 -0800 |
| Message-ID | <ja1ge75jf8v6ecme5ak7lj772uph7u77hf@4ax.com> |
| In reply to | #9208 |
On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <genew@ocis.net>
wrote:
>On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
><med_cutout_syntel@aol.com> wrote:
>
>> Thanks for the code. I'll work on trying to implement it and let you
>>know.
>
> I am going to take another whack at it. I had it working.
>HONEST! REALLY! I thought I had the issue dealt with and so could
>toss the code.
I think I originally had it working with console.log(). I got
the to work when I changed the document.writeln() to console.log().
Does anyone know why the document.writeln() causes Looping() to
become undefined?
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Martin Pearman <warwound@gmail.com> |
|---|---|
| Date | 2011-12-13 23:07 -0800 |
| Message-ID | <6b6f2719-d008-4afe-aff7-9a8595dcae2a@v29g2000yqv.googlegroups.com> |
| In reply to | #9209 |
On Dec 14, 2:10 am, Gene Wirchenko <ge...@ocis.net> wrote: > On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <ge...@ocis.net> > wrote: > > >On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith" > ><med_cutout_syn...@aol.com> wrote: > > >> Thanks for the code. I'll work on trying to implement it and let you > >>know. > > > I am going to take another whack at it. I had it working. > >HONEST! REALLY! I thought I had the issue dealt with and so could > >toss the code. > > I think I originally had it working with console.log(). I got > the to work when I changed the document.writeln() to console.log(). > > Does anyone know why the document.writeln() causes Looping() to > become undefined? > > Sincerely, > > Gene Wirchenko http://www.google.co.uk/search?q=javascript+document+write+clears+page&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a Typically any use of document.write() after the page has loaded will replace the entire page content. So your javascript is wiped out and Looping() is undefined. Martin.
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-14 10:46 -0800 |
| Message-ID | <idrhe79ng7ob331ihhp77q5ffc7o8bqmsk@4ax.com> |
| In reply to | #9210 |
On Tue, 13 Dec 2011 23:07:21 -0800 (PST), Martin Pearman
<warwound@gmail.com> wrote:
>On Dec 14, 2:10 am, Gene Wirchenko <ge...@ocis.net> wrote:
>> On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <ge...@ocis.net>
>> wrote:
>>
>> >On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
>> ><med_cutout_syn...@aol.com> wrote:
>>
>> >> Thanks for the code. I'll work on trying to implement it and let you
>> >>know.
>>
>> > I am going to take another whack at it. I had it working.
>> >HONEST! REALLY! I thought I had the issue dealt with and so could
>> >toss the code.
>>
>> I think I originally had it working with console.log(). I got
>> the to work when I changed the document.writeln() to console.log().
>>
>> Does anyone know why the document.writeln() causes Looping() to
>> become undefined?
>http://www.google.co.uk/search?q=javascript+document+write+clears+page&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a
>
>Typically any use of document.write() after the page has loaded will
>replace the entire page content.
>
>So your javascript is wiped out and Looping() is undefined.
I have a number of pages that do have document.write() calls in
them, and they work fine. The pages are presumably loaded at the time
the document.write() calls are made as some of those are in the body.
In one page, the body consists only of JavaScript code: a variable
creation and four document.write() calls using the variable and a
method defined in the head.
Could you please clarify your response?
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
|---|---|
| Date | 2011-12-14 21:18 +0100 |
| Message-ID | <9ksekdF7jqU1@mid.uni-berlin.de> |
| In reply to | #9226 |
On 14.12.2011 19:46, Gene Wirchenko wrote: <snip> > > I have a number of pages that do have document.write() calls in > them, and they work fine. The pages are presumably loaded at the time > the document.write() calls are made as some of those are in the body. > In one page, the body consists only of JavaScript code: a variable > creation and four document.write() calls using the variable and a > method defined in the head. > > Could you please clarify your response? > In effect you are "overwriting" the old document with a new one, what happens with the "script environment" associated with the old document is anyone's guess, chrome for example guesses it should be kept around, firefox doesn't. But document.write doesn't always mean "overwrite", it can also mean "insert" into what the browser is currently reading and from which it'll build a document. -- Jake Jarvis
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-14 13:30 -0800 |
| Message-ID | <885ie7tuvssco7b61s5rv9ec9lb4c5c78u@4ax.com> |
| In reply to | #9236 |
On Wed, 14 Dec 2011 21:18:21 +0100, Jake Jarvis
<pig_in_shoes@yahoo.com> wrote:
>On 14.12.2011 19:46, Gene Wirchenko wrote:
><snip>
>>
>> I have a number of pages that do have document.write() calls in
>> them, and they work fine. The pages are presumably loaded at the time
>> the document.write() calls are made as some of those are in the body.
>> In one page, the body consists only of JavaScript code: a variable
>> creation and four document.write() calls using the variable and a
>> method defined in the head.
>>
>> Could you please clarify your response?
>>
>
>In effect you are "overwriting" the old document with a new one, what
>happens with the "script environment" associated with the old document
>is anyone's guess, chrome for example guesses it should be kept around,
>firefox doesn't.
>
>But document.write doesn't always mean "overwrite", it can also mean
>"insert" into what the browser is currently reading and from which it'll
>build a document.
So how do I tell that the page has been loaded or that it is not
yet? That page with a JavaScript-only body ends scant bytes after,
and its document.write() calls do not clear the page.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
|---|---|
| Date | 2011-12-14 22:56 +0000 |
| Message-ID | <Xns9FBBF37DF86FDeejj99@194.109.133.133> |
| In reply to | #9239 |
Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
> So how do I tell that the page has been loaded or that it is not
> yet? That page with a JavaScript-only body ends scant bytes after,
> and its document.write() calls do not clear the page.
A page is loaded when all html and direct script is executed and before
body.onload starts executing.
All code that starts after that point and contains ..
document.write()
.. executes an implicit ''
document.open()
.. first,
thereby destroying the loaded document and starting a new document.
Such code starts by an event-listener, like:
onload='myfunction()';
onfocus='myfunction()';
onclick='myfunction()';
setTimeout('myfunction()',milisecs);
etc.
In short, you cannot document.write() into[!!] a page/document
that is ready [="loaded"].
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-14 18:55 -0800 |
| Message-ID | <q3oie7hogiavnms7satu31bi8ct0qu05mc@4ax.com> |
| In reply to | #9242 |
On 14 Dec 2011 22:56:11 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:
>Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
>
>> So how do I tell that the page has been loaded or that it is not
>> yet? That page with a JavaScript-only body ends scant bytes after,
>> and its document.write() calls do not clear the page.
>
>A page is loaded when all html and direct script is executed and before
>body.onload starts executing.
This still is not clear. What is direct script?
I have code that works fine and has document.write() calls in the
body. Other code blows up.
At what point does JavaScript get executed?
Nothing I have read (including the standard) covers this at all
or very well. I have been unable to find any explanation such that,
suing it, I could then look at some code and determine whether it
would wipe out my page or not.
If you have a URL, I will happily read that.
[snip]
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | tony@mountifield.org (Tony Mountifield) |
|---|---|
| Date | 2011-12-15 08:40 +0000 |
| Message-ID | <jccbqm$359$1@softins.clara.co.uk> |
| In reply to | #9256 |
In article <q3oie7hogiavnms7satu31bi8ct0qu05mc@4ax.com>,
Gene Wirchenko <genew@ocis.net> wrote:
> On 14 Dec 2011 22:56:11 GMT, "Evertjan."
> <exjxw.hannivoort@interxnl.net> wrote:
>
> >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
> >
> >> So how do I tell that the page has been loaded or that it is not
> >> yet? That page with a JavaScript-only body ends scant bytes after,
> >> and its document.write() calls do not clear the page.
> >
> >A page is loaded when all html and direct script is executed and before
> >body.onload starts executing.
>
> This still is not clear. What is direct script?
Code that is executed at the time the page is being built, e.g.
<body>
<h1>Test page</h1>
<p>This comes before the hello world.</p>
<script type="text/javascript">
document.write("<p>Hello, world!</p>\n");
setTimeout(function() {document.write("Completely new page\n");}, 5000);
</script>
<p>This comes after the hello world.</p>
</body>
> I have code that works fine and has document.write() calls in the
> body.
As above, yes.
> Other code blows up.
If it gets invoked after the page has finished, by being called by an event
or a timeout.
> At what point does JavaScript get executed?
As it gets encountered. But for any code executed from an event, after the page
has loaded, the document.write calls will replace the page.
In the above example, the function within setTimeout() gets defined as
the page is built, but EXECUTED later.
> Nothing I have read (including the standard) covers this at all
> or very well. I have been unable to find any explanation such that,
> suing it, I could then look at some code and determine whether it
> would wipe out my page or not.
>
> If you have a URL, I will happily read that.
If you want to update parts of your page after it has loaded, then you
don't want document.write(). Instead, you have to manipulate the DOM, by
having empty divs with ids in your document, and then at run time get a
reference to them and either write to their innerHTML property, or attach
new DOM elements to them.
Hope this helps!
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-15 12:08 -0800 |
| Message-ID | <vkkke792atqf0sgm9u9ktcc69h7j2abl6b@4ax.com> |
| In reply to | #9258 |
On Thu, 15 Dec 2011 08:40:54 +0000 (UTC), tony@mountifield.org (Tony
Mountifield) wrote:
>In article <q3oie7hogiavnms7satu31bi8ct0qu05mc@4ax.com>,
>Gene Wirchenko <genew@ocis.net> wrote:
>> On 14 Dec 2011 22:56:11 GMT, "Evertjan."
>> <exjxw.hannivoort@interxnl.net> wrote:
>>
>> >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
>> >
>> >> So how do I tell that the page has been loaded or that it is not
>> >> yet? That page with a JavaScript-only body ends scant bytes after,
>> >> and its document.write() calls do not clear the page.
>> >
>> >A page is loaded when all html and direct script is executed and before
>> >body.onload starts executing.
>>
>> This still is not clear. What is direct script?
>
>Code that is executed at the time the page is being built, e.g.
>
><body>
><h1>Test page</h1>
><p>This comes before the hello world.</p>
><script type="text/javascript">
>document.write("<p>Hello, world!</p>\n");
>setTimeout(function() {document.write("Completely new page\n");}, 5000);
></script>
><p>This comes after the hello world.</p>
></body>
>
>> I have code that works fine and has document.write() calls in the
>> body.
>
>As above, yes.
>
>> Other code blows up.
>
>If it gets invoked after the page has finished, by being called by an event
>or a timeout.
But it is not. It gets invoked in the body. Here is the code
again:
***** Start of Semi-Working Code *****
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>trytimeout.html</title>
<script type="text/javascript">
var i;
function LoopStart()
{
alert("{LoopStart()");
i=1;
setTimeout("Looping()",0);
}
function Looping()
{
alert("{Looping @i="+i);
DoSomething();
if (i%3==0)
document.writeln(i+" thingies somethingerised<br>"); //*****
This causes trouble.
i++;
if (i<=10)
{
alert("@Looping() <setTimeout() @i="+i);
setTimeout("Looping()",0);
alert("@Looping() >setTimeout() @i="+i);
}
}
function DoSomething()
{
for (var i=1; i<=1000; i++)
;
}
</script>
</head>
<body>
<script type="text/javascript">
LoopStart();
</script>
</body>
</html>
***** End of Semi-Working Code *****
So why does the loop not work? IIUC, the LoopStart() call is
executed as it is encountered, and the loop should work. It blows up.
>> At what point does JavaScript get executed?
>
>As it gets encountered. But for any code executed from an event, after the page
>has loaded, the document.write calls will replace the page.
>In the above example, the function within setTimeout() gets defined as
>the page is built, but EXECUTED later.
While the page is still getting set up. So why is it then lost?
>> Nothing I have read (including the standard) covers this at all
>> or very well. I have been unable to find any explanation such that,
>> suing it, I could then look at some code and determine whether it
>> would wipe out my page or not.
>>
>> If you have a URL, I will happily read that.
>
>If you want to update parts of your page after it has loaded, then you
>don't want document.write(). Instead, you have to manipulate the DOM, by
>having empty divs with ids in your document, and then at run time get a
>reference to them and either write to their innerHTML property, or attach
>new DOM elements to them.
I thought that I was generating my page.
>Hope this helps!
Nope.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | tony@mountifield.org (Tony Mountifield) |
|---|---|
| Date | 2011-12-15 20:36 +0000 |
| Message-ID | <jcdloh$mkj$1@softins.clara.co.uk> |
| In reply to | #9273 |
In article <vkkke792atqf0sgm9u9ktcc69h7j2abl6b@4ax.com>,
Gene Wirchenko <genew@ocis.net> wrote:
> On Thu, 15 Dec 2011 08:40:54 +0000 (UTC), tony@mountifield.org (Tony
> Mountifield) wrote:
>
> >In article <q3oie7hogiavnms7satu31bi8ct0qu05mc@4ax.com>,
> >Gene Wirchenko <genew@ocis.net> wrote:
> >> On 14 Dec 2011 22:56:11 GMT, "Evertjan."
> >> <exjxw.hannivoort@interxnl.net> wrote:
> >>
> >> >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
> >> >
> >> >> So how do I tell that the page has been loaded or that it is not
> >> >> yet? That page with a JavaScript-only body ends scant bytes after,
> >> >> and its document.write() calls do not clear the page.
> >> >
> >> >A page is loaded when all html and direct script is executed and before
> >> >body.onload starts executing.
> >>
> >> This still is not clear. What is direct script?
> >
> >Code that is executed at the time the page is being built, e.g.
> >
> ><body>
> ><h1>Test page</h1>
> ><p>This comes before the hello world.</p>
> ><script type="text/javascript">
> >document.write("<p>Hello, world!</p>\n");
> >setTimeout(function() {document.write("Completely new page\n");}, 5000);
> ></script>
> ><p>This comes after the hello world.</p>
> ></body>
> >
> >> I have code that works fine and has document.write() calls in the
> >> body.
> >
> >As above, yes.
> >
> >> Other code blows up.
> >
> >If it gets invoked after the page has finished, by being called by an event
> >or a timeout.
>
> But it is not. It gets invoked in the body. Here is the code
> again:
>
> ***** Start of Semi-Working Code *****
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1" />
> <title>trytimeout.html</title>
>
> <script type="text/javascript">
>
> var i;
>
> function LoopStart()
> {
> alert("{LoopStart()");
> i=1;
> setTimeout("Looping()",0);
> }
>
> function Looping()
> {
> alert("{Looping @i="+i);
> DoSomething();
> if (i%3==0)
> document.writeln(i+" thingies somethingerised<br>"); //*****
> This causes trouble.
> i++;
> if (i<=10)
> {
> alert("@Looping() <setTimeout() @i="+i);
> setTimeout("Looping()",0);
> alert("@Looping() >setTimeout() @i="+i);
> }
> }
>
> function DoSomething()
> {
> for (var i=1; i<=1000; i++)
> ;
> }
>
> </script>
>
> </head>
>
> <body>
>
> <script type="text/javascript">
> LoopStart();
> </script>
>
> </body>
>
> </html>
> ***** End of Semi-Working Code *****
>
> So why does the loop not work? IIUC, the LoopStart() call is
> executed as it is encountered, and the loop should work. It blows up.
The functions get defined in the HEAD before the page is rendered.
OK so far.
The call to LoopStart() happens while the page is being built.
LoopStart() executes at that time. If LoopStart() contained a
document.write(), the output of that would appear within the page.
One of the things that LoopStart() does is to queue a call to Looping()
to be executed at some time in the future, but at least 0ms later.
A setTimeout() with timeout of zero does NOT execute the function
argument there and then.
LoopStart() returns and the page finishes rendering.
Once the page has *finished rendering*, the queued call to Looping()
is then executed. It includes a document.write() which replaces the
displayed page that had already been completed.
The rule is not to use document.write() in ANY function that is
reached via a setTimeout(), setInterval() or an onxxxx event handler.
Only in code that is actually executed (not just defined) while the
page is being built.
Hope this is clearer!
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2011-12-15 15:24 -0800 |
| Message-ID | <n70le79a1ccst08497ugge084fo9f5qctq@4ax.com> |
| In reply to | #9276 |
On Thu, 15 Dec 2011 20:36:33 +0000 (UTC), tony@mountifield.org (Tony
Mountifield) wrote:
[snip]
>> So why does the loop not work? IIUC, the LoopStart() call is
>> executed as it is encountered, and the loop should work. It blows up.
>
>The functions get defined in the HEAD before the page is rendered.
>OK so far.
>
>The call to LoopStart() happens while the page is being built.
>LoopStart() executes at that time. If LoopStart() contained a
>document.write(), the output of that would appear within the page.
Confirmed.
>One of the things that LoopStart() does is to queue a call to Looping()
>to be executed at some time in the future, but at least 0ms later.
>A setTimeout() with timeout of zero does NOT execute the function
>argument there and then.
>
>LoopStart() returns and the page finishes rendering.
>
>Once the page has *finished rendering*, the queued call to Looping()
>is then executed. It includes a document.write() which replaces the
>displayed page that had already been completed.
Got it.
>The rule is not to use document.write() in ANY function that is
>reached via a setTimeout(), setInterval() or an onxxxx event handler.
>Only in code that is actually executed (not just defined) while the
>page is being built.
>
>Hope this is clearer!
Yup! That did it. Thank you very much.
Now, why do I not find this sort of stuff written up in any books
or Website that I read? I only find out because of running into the
problems. Not the most efficient way of going about things, is it?
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott.sauyet@gmail.com> |
|---|---|
| Date | 2011-12-16 06:31 -0800 |
| Message-ID | <b1fa7c11-dede-47c5-9a29-6f2890c7262d@x7g2000vby.googlegroups.com> |
| In reply to | #9285 |
Gene Wirchenko wrote: > Yup! That did it. Thank you very much. > > Now, why do I not find this sort of stuff written up in any books > or Website that I read? I only find out because of running into the > problems. Not the most efficient way of going about things, is it? It's not clear to me why, but the overall quality of Javascript books seems significantly lower than the quality on many other programming topics. For a long time I would only recommend Flanagan's, _Javascript: The Definitive Guide_ and (with some significant caveats), Crockford's _Javascript: The Good Parts_. These days, I'd also include, again with caveats, Stefanov's _Javascript Pattern_ and Zakas' _High Performance Javascript_. I've heard really good things about Haverbeke _Eloquent Javascript_ as a beginner's book, but I haven't really been through it. As to websites, there is plenty of good stuff out there. But there is much, much more that is pure nonsense, or, worse, only pseudo- sensible. Anyone who has made something `work` on a webpage with JS seems to think that immediately qualifies them as an expert, and they publish much rubbish. The best way to learn this stuff is to continually experiment, post in groups like this one and jsmentors, read one or two of the books above, and most of all, just keep trying. If you want other online resources, the `blogs` section of Rey Bango's post lists many good resources: <http://blog.reybango.com/2010/12/15/what-to-read-to-get- up-to-speed-in-javascript/> Good luck, -- Scott
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1150@merlyn.demon.co.uk> |
|---|---|
| Date | 2011-12-16 21:17 +0000 |
| Message-ID | <Z4ipXeGYV76OFwDH@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #9285 |
In comp.lang.javascript message <n70le79a1ccst08497ugge084fo9f5qctq@4ax.
com>, Thu, 15 Dec 2011 15:24:04, Gene Wirchenko <genew@ocis.net> posted:
> Now, why do I not find this sort of stuff written up in any books
>or Website that I read? I only find out because of running into the
>problems. Not the most efficient way of going about things, is it?
As far as I recall we know, you are relying on one very old book, which
you have not named.
Consider first a plain HTML page. It is a nested structure of elements,
with an element represented by <tag> ... </tag> - though in some cases
(like <p>) the </tag> is not necessary in the HTML, as the parser can
see where it must be; and in other cases (like <hr>), where there is no
... part, there may be no closing tag.
That nested-box structure is equivalent to a tree structure, which is
easier to think about. As time permits, that tree will be rendered on
the screen. AIUI, script execution can interrupt rendering, but
rendering cannot interrupt script.
One particular box is the <script> box.
As the page source is read from wherever, with included files treated as
if in the source, it is parsed and the DOM tree is built. Scripts found
are immediately executed. Some pieces of script merely do internal
operations like arithmetic or string-twiddling. Function statements
merely define functions, ready to be called. Statements document.write
and document.writeln add to the DOM tree. Statements can, by using
getElementById, walking the DOM tree, or using quasi-arrays such as
forms, alter the DOM tree; but they can only alter what already exists.
When the end of the source is reached, no further code is executed,
except as a result of an event. Events are chiefly the result of mouse-
clicks, or of keyboard actions, or are caused by setTimeout expiring or
setInterval ticking (there may be others).
In event code, any unqualified document.write and document.writeln
writes to the current window, essentially uprooting the old DOM tree and
beginning a new DOM tree (it is possible that scripts or include files
may survive in some or all browsers).
NOTE : I/O elements within a Form [commonly] have a property 'form'
which is effectively a pointer to the form. There is also a property
'this'.
Consider as an illustration an on/off button in a form
<input type=button value=1 onclick="Cluck(this)">
with already constructed
function Cluck(Me) {
(Me.value ^= 1) ? StopJob(Me.form) : StartJob(Me.form) }
Pressing the button toggles its value (I'm assuming buttons labelled
with 0 & 1 are known in BC) and starts or stops the Job (possibly in the
other order); and the job code has access to the value of Me.form which
it can use to read/write the Form.
The code has been tested.
I don't doubt your statement that there is nothing like that on the Web
that you can find; but you should not make such a statement again.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
|---|---|
| Date | 2011-12-15 11:03 +0000 |
| Message-ID | <Xns9FBC7AB347CCEeejj99@194.109.133.133> |
| In reply to | #9256 |
Gene Wirchenko wrote on 15 dec 2011 in comp.lang.javascript: >>> So how do I tell that the page has been loaded or that it is not >>> yet? That page with a JavaScript-only body ends scant bytes after, >>> and its document.write() calls do not clear the page. >> >>A page is loaded when all html and direct script is executed and before >>body.onload starts executing. > > This still is not clear. What is direct script? Direct/immediate script execution = execution before the page is fully loaded. "loaded" means built. Listener "onload" should have been called "onloaded". Perhaps some experimenting experience will do better than explaining. You are skipping what I wrote about code that is only executed by a trigger from a event-listener or timeout execution. And that is just the crux. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1150@merlyn.demon.co.uk> |
|---|---|
| Date | 2011-12-15 20:42 +0000 |
| Message-ID | <DlO$QZIoul6OFwA1@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #9236 |
In comp.lang.javascript message <9ksekdF7jqU1@mid.uni-berlin.de>, Wed, 14 Dec 2011 21:18:21, Jake Jarvis <pig_in_shoes@yahoo.com> posted: >On 14.12.2011 19:46, Gene Wirchenko wrote: ><snip> >> >> I have a number of pages that do have document.write() calls in >> them, and they work fine. The pages are presumably loaded at the time >> the document.write() calls are made as some of those are in the body. >> In one page, the body consists only of JavaScript code: a variable >> creation and four document.write() calls using the variable and a >> method defined in the head. >> >> Could you please clarify your response? >> > >In effect you are "overwriting" the old document with a new one, what >happens with the "script environment" associated with the old document >is anyone's guess, chrome for example guesses it should be kept around, >firefox doesn't. > >But document.write doesn't always mean "overwrite", it can also mean >"insert" into what the browser is currently reading and from which >it'll build a document. It never inserts. It appends to as much of the DOM representation has already been constructed, and that which is constructed later follows it. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links; Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc. No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1150@merlyn.demon.co.uk> |
|---|---|
| Date | 2011-12-14 21:11 +0000 |
| Message-ID | <cA0o5PPBER6OFwAq@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #9190 |
In comp.lang.javascript message <9kpg77Fu2fU1@mid.individual.net>, Tue, 13 Dec 2011 10:26:34, Mel Smith <med_cutout_syntel@aol.com> posted: > > The only problem I have is displaying a 'Waiting for Sort to Complete >...' message on the screen during the interval that sorting is taking place. Display the message as the last thing but one that gets executed. The last thing is a setTimeout that calls the sort routine after some short interval, say 100 ms. At the end of the sort, remove or alter the wait message. -- (c) John Stockton, nr London, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web