I am trying to insert text from a *.txt
file into a google site.
this is what i have tried so far (using fetch
), but my search is exhausted:
<html>
<body>
<div id="text-container"></div>
<script>
fetch("G:/My Drive/path/to/test_file/test.txt")
.then(response => response.text())
.then(text => {
document.getElementById('text-container').innerHTML = text;
});
</script>
</body>
</html>
But all I get is a blank.
I know the text file exists because i can embed the whole file (from the same location), but i just want to extract the relevant text into the google site and not the whole file (which is an undesired alternative).
I see that other answers that require GOOGLE API (from 2017) are potentially available here as a workaround, but do not appear to work now (in 2023): JavaScript read all text from txt file on Google drive or Dropbox
But this would be rather cumbersome for extracting small pieces of text.
How can this be achieved?
Note: The text file lives in Google Drive. I can embed the entire file (which looks rather ugly, link to a file), so I want to take just the text content into the html... both the Google Site and the text document are in the same folder.