Premise
- I am not much expert in this, but I have superficial familiarity with HTML, CSS, vanilla JS.
- I am creating for let say for myself an application in HTML 5, CSS 3, vanilla JS ECMA script 6, so with NO use of frameworks as jQuery or else: just vanilla JS, and I also don't care about older browser that are not HTML 5 ES6 CSS 3 compliant, like IE.
- The application runs as simple HTML/CSS/JS file on the local computer only: so no remote server is involved but it is a portable app I store and use on my computer or on a pen drive or I send to other people as my family to show things to them.
- I know about limits imposed to HTML/JS to open files on its own and about the need for user interaction by the use of input type="file" html element... but nevertheless might be there is another way I am not familiar with yet, if I'm lucky...
Situation
- I have an already working html file, let's call it Manager.html. It contains a table that is populated with a list of files, listed as:
- File 1.db
- File 2.db
- File 3.db
- and much much more of them...
Also, each file is a URL, for instance:
<a href="file 1.db">file 1.db</a>
If I have to, I can change their extension to *.json, *.csv, *.tsv, *.db, *.txt, or any other that could work as long as it is a data related extension for files containing text only, no problem at all for that.
I have an already working html file that acts as a viewer let's call it Viewer.html: it loads data from those other db files by using at the moment a canonical input type="file". It loads the content of the chosen database and displays it into the table handled by Manager.html and the relative js that handles the loading process and the process to populate the table.
The db file used is a custom kind of "csv"-like-file (coma separated value format file) customized by myself: it contains basically text only content and uses normal \CR\LF to separate records and the pipe symbol "|" (no double quotes) instead of commas, for separating fields. For instance:
- text of field 1|text of field 2|text of field 3|text of field n
- text of field 1|text of field 2|text of field 3|text of field n
- text of field 1|text of field 2|text of field 3|text of field n
- and more records ...
The content of the db files is utf8 text and it is not limited in quantity, so:
- a db file could be of any size: from few Bytes or KB and few records or even hundreds or thousands of KB and hundreds or even thousands of records: so can be present any number of records.
- a record could be any length, with a fixed number of fields, corresponding to the number of fields of the target html table in Viewer.html
- a field can contain text of any length as well
At the moment everything works well per se with the input type="file" implementation, but I want to implement a different feature and improve my user experience because at the moment I have to:
- open Viewer.html
- here I have to click on the input type="file" control to open the "open file window"
- from the "open file window" I have to select the File n.db file I wish to load in Viewer.html to open it and populate the table into Viewer.html.
All this is of course super tedious.
So what I want is to be able to:
Of course directly from Manager.html, that holds the table with the main list of all File n.db I want just to:
- click on the url of the File n.db file I want to open, listed inside the table in the file Manager.html. And with that just one click I want the javascript to:
- open the Viewer.html
- pass to Viewer.html as parameter the File n.db file to be processed
- Viewer.html opens it by its own, process it, and shows its content into its table.
In other words I'm looking for a function that can do something similar to:
Pseudo code:
open(Viewer.html, File n.db)
will also work as well something similar to:
<database src="MyDBsubDir/MyDBfile.db"></database>
Would be great if it works with standard db files as csv, tsv, json, db, txt, and so on, containing just Unicode text in it.
It is relevant/Crucial
- The use of the Manager.html to list all File n.db files to click on for opening.
- The use of just one common Viewer.html, so it will be easier to maintain and in case of need could be updated just once for debugging or to implement new features in case of need.
- Handle an unlimited number of File n.db files (or with other extensions)
Questions
- Is it possible for the user (typically myself or family or friends) which is showing Manager.html click on a link of the file and pass its href value as parameter to the other file Viewer.html to be processed and shown here?
- If Yes, how do I implement a function that does something like that in vanilla JS?
Basically the function activated on mouse click on the link will have to get the text content of the file n.db file under the href attribute of the same clicked link, and will "inject" / "fuse" on the fly such a content with the Viewer.html itself that will provide the correct formatting of it as html table so can be shown on the browser as a normal html page instead of just text.
Notice that
As already said: the solution I'm looking for, if any, must be compatible with only HTML 5, ES6 compliant browsers (so I really don't care about IE and similar others, which are dead for me). I repeat: all has to work on a "local" machine (Windows, Linux, MAC, Android... and more), no server of any kind has to be involved.
The ideal solution would be a fetch() like function if it worked on local files, but unfortunately it doesn't, as far as I know.
Also it doesn't work either to compile by JavaScript a input type=file with the file because of course it is not allowed for security reasons.
Ideal behavior
IMHO the best way to go to solve this limit once and for all without putting in jeopardy the security of the local system, would be to implement in all browsers a standard behavior that asks to the user the authorization to access to app directory and its sub-dirs, similarly as when the browsers ask the user for authorization to use the microphone. This will allow the user to decide if a local app is authorized to access to its own directory. This authorization has to be a per-session authorization: so it is given every time the app is opened into the browsers.