0

I am fairly new to HTML, and I am trying to make a HTML page that constantly reads a text file, so that when the contents of the text file are changed, the HTML page will also change to reflect it. My current code is as follows;

<!DOCTYPE html>
<html>
<title>File Contents</title>
<h1>File contents of input.txt<br>Below are the contents of the file input.txt, in the same directory as this file</h1>
<div><object data="Input.txt"></object></div>
</html>

However, this script only loads the text file once, and any subsequent modifications will not be shown.

Is there any way to do this with just HTML and Javascript?

1 Answer 1

1

This script will reload the <object> every 10 seconds (10000 ms).

<!DOCTYPE html>
<html>
<title>File Contents</title>
<h1>File contents of input.txt<br>Below are the contents of the file input.txt, in the same directory as this file</h1>
<div><object data="Input.txt"></object></div>
<script type="text/javascript">
setInterval(() => {
    let obj = document.getElementsByTagName('object')[0];
    obj.setAttribute('data', obj.getAttribute('data'));
}, 10000);
</script>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.