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


Groups > comp.lang.javascript > #38368

Re: Reading a local file from an HTML page

Newsgroups comp.lang.javascript
Date 2020-04-04 05:41 -0700
References <4830286f-4484-49f8-9cda-9a4073ab6502@googlegroups.com> <b6ad961f-1dad-4bef-9db9-977a096f2b33@googlegroups.com> <2c9a81c5-d18c-4fc2-8df0-5524e03d5c21@googlegroups.com> <5a252de6-a912-49c3-a405-81e9d2ae15a7@googlegroups.com>
Message-ID <6593cb89-098d-484d-a8ff-aced40d041f5@googlegroups.com> (permalink)
Subject Re: Reading a local file from an HTML page
From dr.j.r.stockton@gmail.com

Show all headers | View raw


On Saturday, 4 April 2020 01:11:07 UTC+1, Michael Haufe (TNO)  wrote:
> On Friday, April 3, 2020 at 5:24:34 PM UTC-5, dr.j.r...@gmail.com wrote:

> > ...
> > ... So what I need is
> > 
> > function GetDomTree(FileName) { // File will exist
> >   // code
> >   return DomTree }
> > 
> > or something like
> > 
> > function GetDomTree(FileName) { // File should exist
> >   // code with try ... catch
> >   return FileExists ? DomTree : null }
> > 


Remember that this is a page that I've been using for a long time, and it was necessarily written in that subset of old JavaScript that I then knew.

> It sounds to me you're just trying to build a sitemap. Why not simply crawl the site from index.html and validate the links?

No. I don't want a sitemap; though I do the surveying that a map would need, I don't keep enough observations for a map.  I do crawl the site, generally from INDEX.HTM, and validate the links.  I also validate any other connections, such as <IMG SRC="AAA.KPQ"> - or at least such as I know how to find.  I also report the content of various lists built during processing.
 
> Perform Breadth-First-Search on the document.links of the document where index.html is the start.

I have what I think is an excellent reason for not *necessarily* starting at INDEX.HTM - I can start at another page containing one or more intentional errors, in order to test what the code actually does in those cases; that page does not need to link to any other existing pages.  Also, I have a file, created at each boot or later, which contains links to all *.HTM files in the folder, about 30% of which are not on the main site; testing that has its uses.

> Then for each link attempt to fetch the target to see if it exists.

I use my directory file to see if the target exists, because I did not know how to deal with the "File Not Found" case.  I don't need to improve on that, because it works.  I suppose that you would suggest try...catch - but then to test the Not Found case I would need either to create a link to a non-file or hide a file, and it's easier to falsify the directory file, which can be recreated in the time needed for a click and six keystrokes.
 
> You can store the results in localStorage for future use. 

No need, and I don't know how to.
 
> This should eliminate the need for a BAT file as well as issues with CORS.

I knew nothing of CORS.  It appears to be about WEB pages, from servers, only.


But I need to have one (or both) of the GetDomTree functions, because I have the name of a file and I want to be able to read the DOM tree which that file generates when loaded. ... thought ... research ... I certainly want to read parts of the Document Object - the links and anchors arrays ---  I want to read the contentDocument.

So I need a getContentDocument(FileName) function, where the named file is directly accessible to the current user of the device - it will be in the current folder of the page that is running, or in the folder tree rooted in that current folder.

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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Reading a local file from an HTML page dr.j.r.stockton@gmail.com - 2020-04-02 13:29 -0700
  Re: Reading a local file from an HTML page minajaich@gmail.com - 2020-04-02 18:59 -0700
  Re: Reading a local file from an HTML page JJ <jj4public@vfemail.net> - 2020-04-03 20:18 +0700
  Re: Reading a local file from an HTML page "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-04-03 10:57 -0700
    Re: Reading a local file from an HTML page dr.j.r.stockton@gmail.com - 2020-04-03 15:24 -0700
      Re: Reading a local file from an HTML page "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-04-03 17:11 -0700
        Re: Reading a local file from an HTML page dr.j.r.stockton@gmail.com - 2020-04-04 05:41 -0700
      Re: Reading a local file from an HTML page "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-04-04 12:17 +0200
  Re: Reading a local file from an HTML page "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-04-06 17:01 -0700
    Re: Reading a local file from an HTML page dr.j.r.stockton@gmail.com - 2020-04-13 12:11 -0700
      Re: Reading a local file from an HTML page "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-04-14 10:04 -0700

csiph-web