Search code examples
javascripthtml-object

Is there any way to console.log the content of an html object?


Let's consider we have two files namely object.html & load.txt.

object.html

  <!DOCTYPE html>
  <body>
    <object data="load.txt"></object>
  </body>
  </html>

load.txt

   You have to load me !

Now, when I open the object.html in browser window, the content of load.txt file is shown ( as usual ), but I want the content also to show in the console, saying "The content of the text file you loaded :" and the content after that. But I am not understanding, how to console.log the content of the txt file. Can you help me ?


Solution

  • You cannot directly console.log() the content of the file.

    For that, you need to read the content of the file using the FileAPI and then console.log() the content.

    For further you can read in much detail about the console.log the content of the file in javascript in this answer