All I’ve found is how to display the data of the TXT file, but I want to be able to use that TXT file to be interpreted and used as HTML code to be displayed instead.
All I’ve found is how to display the data of the TXT file, but I want to be able to use that TXT file to be interpreted and used as HTML code to be displayed instead.
3
Answers
Change the file suffix to
.html
instead of.txt
If you mean JavaScript, your only option would be to do something like this:
Note that
eval
ornew Function
is not safe and should not be used in most cases.I used a very slightly modified version of derder56‘s code for this example that takes HTML code from a text file and outputs it in the
result
div. Of course, you could do anything with the result from the text file, such as outputting it in the console.Keep in mind that due to a CORS security advisory, you wouldn’t be able to do this with local files due to CORS requests requiring HTTP or HTTPS.