0

I am new to HTML and JS - so to learn I have been building a HTML page (saved in a .htm file in a shared drive which is accessible to my team). This page is basically a table of web links useful for new employees.

While the table of links is extensive, we need the ability to add new links when needed, so I have built in an AddToTable() function where users can add new links by adding to the table. (I guess I will address the deletion of a table item at a later date...)

The trouble is, because we load this page from a local shared drive, when a user adds to the table, that information never gets written to/saved in the .htm file.

In fact, the "new" information only appears in the underlying HTML if I save the page as "Web Page, complete".

Which brings me to my question: Is there JS I could append to my AddToTable() function that would

  • Save page as "Web Page, complete" as the same file name of the source .htm file
  • Reload the page from that "new" source .htm file

Thanks!

kroy2008
  • 175
  • 1
  • 11
  • You cannot add add/append content directly to a static file (Like .html) for this you must use data base and then load the content from database – Sarath Damaraju Aug 27 '18 at 12:01
  • 1
    No, client-side JavaScript executed in the context of a web page can not do that directly. At most you could trigger a file download via JavaScript, but the user would still have to select where to store the file manually (resp. it will go to the default download location specified in the browser.) This is not a task that should be attempted in client-side JavaScript to begin with, you want a server-side component for this. – CBroe Aug 27 '18 at 12:02
  • Thanks @CBroe and Sarath. I don't have the ability to store this on a server. So out of curiosity, how would I trigger a download of the "Web Page, complete" with JS? – kroy2008 Aug 27 '18 at 13:21
  • “Web page, complete” in that it also stores all external resources in a sub-directory will hardly be possible (unless you want to implement a “container” format like ZIP in JS first, and then fill it accordingly.) But if you only need to change links in the content, then you don’t need to save all other resources each time, the HTML file itself would be sufficient. A way of doing this can be found here, https://stackoverflow.com/q/7271524/1427878 (you’d have to check if that still works, browsers have introduced more restrictions on Data URIs since.) – CBroe Aug 27 '18 at 13:30

1 Answers1

0

Wouldn't it be better to save your table into a text file and then read it from there every time? (Best would be a database for this purpose, but I guess you don't want to deal with that because of the size of the project.)

Lricsi
  • 36
  • 11
  • This should be posted as a comment since it doesn't really answer the question or solve the current problem. This is more of a suggestion than a solution. – NewToJS Aug 27 '18 at 12:09