Richard Horrocks
Richard Horrocks

Reputation: 439

How to manipulate a local text file from an HTML page

I've generated an HTML file that sits on my local disk, and which I can access through my browser. The HTML file is basically a list of links to external websites. The HTML file is generated from a local text file, which is itself a list of links to the remote sites.

When I click on one of the links in the HTML document, as well the browser loading the relevant site (in a new tab), I want to remove the site from the list of sites in the local text file.

I've looked at Javascript, Flask (Python), and CherryPy (Python), but I'm not sure these are valid solutions. Could someone advise on where I should look next? I'd prefer to do this with Python somehow - because it's what I'm familar with - but I'm open to anything.

Note that I'm running on a Linux box.

Upvotes: 0

Views: 1054

Answers (2)

wersimmon
wersimmon

Reputation: 2869

First, Javascript cannot modify the local filesystem from the context of a webpage. To allow that would be a massive security concern.

Any server-side web framework can do this, and Flask is a great one to use because it's so lightweight. The general steps you would want to take are:

  1. When / is requested, load the list of links.
  2. Change each link to point to /goto?line=<line_number>.
  3. Display the list to the user.

Then when you click a link:

  1. When /goto is requested, load the list of links.
  2. Remove the line number from the list.
  3. Save the list of links.
  4. Return status code 302, with the real URL as the Location header.

Upvotes: 1

Steven Martin
Steven Martin

Reputation: 3290

There is many ways to do this

Here is the easiest 3

  1. Use JavaScript

2 install wampserver or similar and use php o modify the file

3 don't use te browser to delete and instead use a bat file to open the browser and remove the link from the text file

Upvotes: 0

Related Questions