0

I have HTML file with body like this:

<body>
     <div><object data="file.txt" id="data"></object></div>
</body>

This code shows the text from the file in the browser, but I'm unable to access the text from javascript. I tried '.text', '.innerHtml', '.innerText', '.textContext' and so on but I can't access it.

I need to parse the lines from the text file. Other methods of including text file into HTML which I found online didn't work at all, this is the only one that actually displays the data.

Can you advice me how to get the text to Javascript? Using plain JS please. Thank you.

Yoan
  • 2,158
  • 1
  • 12
  • 21
lsrom
  • 608
  • 8
  • 22
  • 2
    You can't, for security reasons. –  Dec 24 '16 at 18:27
  • 2
    Using an `iframe` or getting the file with AJAX are both better alternatives to this approach. – Scott Marcus Dec 24 '16 at 18:27
  • 1
    can use ajax to retrieve the file and parse it in success callback – charlietfl Dec 24 '16 at 18:29
  • 1
    iframe doesn't work either: Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame. I want solution as simple as possible so Ajax is out of a question. It should be all in one static HTML page with one text file as resource. – lsrom Dec 24 '16 at 18:53

0 Answers0