Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #37035 > unrolled thread

Clearing/Writing a daughter window ?

Started bydr.j.r.stockton@gmail.com
First post2019-08-03 10:46 -0700
Last post2019-08-08 15:00 +0200
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Clearing/Writing a daughter window ? dr.j.r.stockton@gmail.com - 2019-08-03 10:46 -0700
    Re: Clearing/Writing a daughter window ? "R.Wieser" <address@not.available> - 2019-08-04 09:47 +0200
    Re: Clearing/Writing a daughter window ? JJ <jj4public@vfemail.net> - 2019-08-06 00:32 +0700
      Re: Clearing/Writing a daughter window ? dr.j.r.stockton@gmail.com - 2019-08-06 04:13 -0700
        Re: Clearing/Writing a daughter window ? JJ <jj4public@vfemail.net> - 2019-08-07 21:27 +0700
      Re: Clearing/Writing a daughter window ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-08-08 15:00 +0200

#37035 — Clearing/Writing a daughter window ?

Fromdr.j.r.stockton@gmail.com
Date2019-08-03 10:46 -0700
SubjectClearing/Writing a daughter window ?
Message-ID<2e2a80c3-e3bb-4e10-8be1-48c21f76f441@googlegroups.com>
OK, my test HTA can now open and close daughter windows,
and can write to them.

But I want to clear and refill a daughter window, rather
than closing a daughter and opening a new one, which I
suspect of being slower.

The following code, as expected, puts both pages into
the one window, 3 following 2 (sections 2 & 3 differ
only in their digit).

Other than closing Wndw and opening another Wndw, is
there something that I can put as position X to restore
Wndw to the freshly-opened state?

Alternatively, is there a better way of loading sFileDat
into Wndw, maybe by assignment, so that any previous content
of Wndw is no longer there (and best, given explicitly
to the garbage collector)?

There will be a few hundred executions of opentextfile as
the script's attention roams from page to page.



// 1
Wndw = window.open("", "Y"+new Date().getTime(), "")

// 2
sSrcFile = "C:\\homepage\\zel-82px.htm"
oSrcFile = fso.opentextfile(sSrcFile, ForReading) 
sFileDat = oSrcFile.ReadAll()
oSrcFile.Close()

Wndw.document.writeln(sFileDat)

// X

// 3
sSrcFile = "C:\\homepage\\zel-83px.htm"
oSrcFile = fso.opentextfile(sSrcFile, ForReading) 
sFileDat = oSrcFile.ReadAll()
oSrcFile.Close()

Wndw.document.writeln(sFileDat)

// ...

-- 
  (c) John Stockton, near London, UK.  Using Google Groups.           |
 Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

[toc] | [next] | [standalone]


#37037

From"R.Wieser" <address@not.available>
Date2019-08-04 09:47 +0200
Message-ID<qi62jn$1v7f$1@gioia.aioe.org>
In reply to#37035
John,

> Other than closing Wndw and opening another Wndw,
> is there something that I can put as position X to restore
> Wndw to the freshly-opened state?

As far as I can tell you can remove all elements from the page.   But that 
won't clear variables ...

In JS it goes like this (executed on the page itself.  I assume that 
replacing "document" with your "WindW" will access your "daughter window". 
But if not try "WindW.document"  ):

aElements = document.children
for (var i=aElements.length;i--;i>=0) 
aElements[i].parentNode.removeChild(aElements[i]);

(notice the for loop starting from the end and decrementing 
upto-and-including zero)

It clears all direct children, in with it the childrens contents too. 
Should take just two steps (header and body elements).

No idea as how to translate that to VBS though. Sorry.

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#37048

FromJJ <jj4public@vfemail.net>
Date2019-08-06 00:32 +0700
Message-ID<n6pu9j06ak6h$.12cebyy4gv9a7$.dlg@40tude.net>
In reply to#37035
On Sat, 3 Aug 2019 10:46:30 -0700 (PDT), dr.j.r.stockton@gmail.com wrote:
> OK, my test HTA can now open and close daughter windows,
> and can write to them.
> 
> But I want to clear and refill a daughter window, rather
> than closing a daughter and opening a new one, which I
> suspect of being slower.
> 
> The following code, as expected, puts both pages into
> the one window, 3 following 2 (sections 2 & 3 differ
> only in their digit).
> 
> Other than closing Wndw and opening another Wndw, is
> there something that I can put as position X to restore
> Wndw to the freshly-opened state?
> 
> Alternatively, is there a better way of loading sFileDat
> into Wndw, maybe by assignment, so that any previous content
> of Wndw is no longer there (and best, given explicitly
> to the garbage collector)?

You should call the `document.close()` after you've finished using either
`document.write()` or `document.writeln()`. Once `document.close()` is
called, the next time you call `document.write()` or `document.writeln()`
again, it will rewrite the whole page. i.e. the old page contents is
discarded.

Keep in mind though... That, this only applies to HTML elements. It won't
apply to any previously declared JavaScript variables and functions. If you
want a truly fresh page, navigate the window via its window object.

[toc] | [prev] | [next] | [standalone]


#37051

Fromdr.j.r.stockton@gmail.com
Date2019-08-06 04:13 -0700
Message-ID<c0fc9474-a6d8-47fb-b490-d663a0d22a81@googlegroups.com>
In reply to#37048
On Tuesday, 6 August 2019 10:40:56 UTC+1, JJ  wrote:
> On Sat, 3 Aug 2019 10:46:30 -0700 (PDT), JRS wrote:
> > OK, my test HTA can now open and close daughter windows,
> > and can write to them.
> > 
> > But I want to clear and refill a daughter window, rather
> > than closing a daughter and opening a new one, which I
> > suspect of being slower.
> > 
> > The following code, as expected, puts both pages into
> > the one window, 3 following 2 (sections 2 & 3 differ
> > only in their digit).
> > 
> > Other than closing Wndw and opening another Wndw, is
> > there something that I can put as position X to restore
> > Wndw to the freshly-opened state?
> > 
> > Alternatively, is there a better way of loading sFileDat
> > into Wndw, maybe by assignment, so that any previous content
> > of Wndw is no longer there (and best, given explicitly
> > to the garbage collector)?
> 
> You should call the `document.close()` after you've finished using either
> `document.write()` or `document.writeln()`. Once `document.close()` is
> called, the next time you call `document.write()` or `document.writeln()`
> again, it will rewrite the whole page. i.e. the old page contents is
> discarded.

I should have thought of that - certainly good, *thanks*.


> Keep in mind though... That, this only applies to HTML elements. It won't
> apply to any previously declared JavaScript variables and functions.


I don't think that matters.  In theory, I ought to wait until the
body.onload() has finished before reading the links and anchors
collections.

A few of my pages, those about VBScript, contain non-JavaScript
variables and functions!

> If you
> want a truly fresh page, navigate the window via its window object.

I would prefer a truly fresh page, in case it ever matters; but I don't understand how to do that navigation.


-- 
  (c) John Stockton, near London, UK.  Using Google Groups.           |
 Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

[toc] | [prev] | [next] | [standalone]


#37056

FromJJ <jj4public@vfemail.net>
Date2019-08-07 21:27 +0700
Message-ID<1hmb4b64yyxa0$.d9zdjhknacr0$.dlg@40tude.net>
In reply to#37051
On Tue, 6 Aug 2019 04:13:01 -0700 (PDT), dr.j.r.stockton@gmail.com wrote:
> 
> I would prefer a truly fresh page, in case it ever matters; but I don't understand how to do that navigation.

Normally, the `location.href` is reassigned with a new URL. Or just call the
`navigate()` method. ... of the window object. e.g.

    window.navigate("d:\progs\app2.hta")

Or...

    window.location.href = "d:\progs\app2.hta"

However, this is not possible from HTA. Mother/parent windows can't do that
for their daughter/child windows. Only the code in the child window can do
it. It's a stricter security, in comparison with web browsers.

The only workaround I could think of is to use a file to command the
daighter window. The file would contain a line of command, then the
following line(s) would be the command's argument(s). e.g.

    navigate
    d:\progs\app2.hta

Or just a single line of an URL, if only page navigation is needed.

At initialization, the daughter window would setup a timer where it
periodically checks the presence of that file. Both the parent and child
windows must agree on the same file name & path. When the file is found, it
would read it, delete it, then performs the command using the above
mentioned. If the file is found, but can't be opened, it means that the file
is being written. So, ignore it and let the next file check is performed. A
one or half second timer duration should be enough.

File management can be done using the `Scripting.FileSystemObject` object.

[toc] | [prev] | [next] | [standalone]


#37057

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2019-08-08 15:00 +0200
Message-ID<1865052.oMNUckLgyt@PointedEars.de>
In reply to#37048
JJ wrote:

> On Sat, 3 Aug 2019 10:46:30 -0700 (PDT), dr.j.r.stockton@gmail.com wrote:
>> Alternatively, is there a better way of loading sFileDat
>> into Wndw, maybe by assignment, so that any previous content
>> of Wndw is no longer there (and best, given explicitly
>> to the garbage collector)?
> 
> You should call the `document.close()` after you've finished using either
> `document.write()` or `document.writeln()`. Once `document.close()` is
> called, the next time you call `document.write()` or `document.writeln()`
> again, it will rewrite the whole page. i.e. the old page contents is
> discarded.

That document.write() implicitly calls document.open() is only standardized 
since HTML5.

The safe way is to call

  child_window.document.open();

before document.write() explicitly.

Note however, that this is the crude, outdated way to reset the entire 
contents of a window; for backwards compatibility, you will have to
restore the *entire* document, including the HEAD element.

Since the MSHTML and W3C DOMs, there is

  document.body.textContent = '';

or

  var body = document.body;
  var last_child;
  while ((last_child = body.lastChild)) body.removeChild(last_child);

or its MSHTML and W3C DOM Working Draft variant

  document.body.innerHTML = '';

instead.  The latter is probably the only reasonable use for the as-yet 
proprietary “innerHTML” property if none of the previous variants can be 
used.
 
> Keep in mind though... That, this only applies to HTML elements. It won't
> apply to any previously declared JavaScript variables and functions. If
> you want a truly fresh page, navigate the window via its window object.

If none of the above approaches suffice, it should be easier to call

  child_window.location.reload(true);

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web