N
N
Nazarevsky2021-07-10 11:14:06
HTML
Nazarevsky, 2021-07-10 11:14:06

Is it possible to add code to the HTML file itself?

Hello!
The other day I asked myself a very strange question. Is it possible to use HTML code as a database (XML type). I mean, is it possible to add, remove elements to the code itself , creating tags, and generally edit the file itself?
It will be very interesting to hear my answer!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
ThunderCat, 2021-07-10
@Nazarevsky

Not a very clear question...
In theory - yes, you can change the html file with another server language and save it in this form. In practice, this is a terrible crap, since it is easier to store the data separately, and the view separately, because the view can change, or even be absent (for example, in the API).
If we are talking about a local file and changing it from itself, then no, by means of modern browsers it (thank eggs) cannot be saved locally from the code, otherwise it would be possible to save absolutely any files to an arbitrary machine, which I personally would not wish anyone. Only handles, but the changes made will not be saved.
As a freak project, the first option is quite working, and the option proposed by Vladimir Korotenkowill work locally as well, although everything will not be stored in the file itself, that is, data portability is zero, so there is no need to talk about storage "like in a database".

V
Vladimir Korotenko, 2021-07-10
@firedragon

The script builds the data in localstporadje based on their interface, but this is purely for one. But if you add a little server logic, then everything will work everywhere

N
Nadim Zakirov, 2021-07-10
@zkrvndm

Yes, you can. You can insert the data to be stored into the body of the document as a base64 file. You can give the document itself for download on some condition, for example, offer to save changes after each significant edit. This is not very convenient, but in this way it is quite possible to create a small web application in the form of a self-editing html file.
PS But in fact it is done a little differently. If you want to create programs in HTML and JavaScript, then there is such a thing as Electron - this is a special browser without controls. You make your own program (like a regular site) and wrap it in Electron, get an .exe to run as an output.

D
Dmitry, 2021-07-10
@thewind

They give you some strange answers ... you ask about changing the document in the browser through another language?
https://tproger.ru/translations/dom-javascript/ - for javascript please

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question