Ben
Ben

Reputation: 849

Is it possible to use document.innerHTML to print out a .txt file?

Is it possible to use document.innerHTML to print out all the text from a .txt file? I'm trying to swap all the code in the c1 anchor from this

<div class="bigtext">
    <a id="c1"><img src="portraits/Random_0.jpg" width="60px" height="60px" alt=random></img>Random</a>
    </div>

to this

<div class="bigtext">
    <a id="c1"><img src="portraits/Otherthing_0.jpg" width="60px" height="60px" alt=random></img>Other Thing</a>
    </div>

I'm calling this Javascript function that gets triggered when pressing on a picture using onClick()

   function bubby() {
document.getElementById('c1').innerHTML=(text.txt);
}

But it's not working properly, it works when I do the innerHTML command in quotes but that only seems to work for small pieces of text, and I need to print out lines of code with quotes in them.

Upvotes: 0

Views: 143

Answers (1)

Vitalii Petrychuk
Vitalii Petrychuk

Reputation: 14255

It's not possible to access file system. So, NO.

As workaround you can fetch a content of the file using XHR and append it to the #c1 element.

Upvotes: 1

Related Questions