www.webdeveloper.com
Results 1 to 7 of 7

Thread: Read txt file using javascript and display the content in simple html file

  1. #1
    Join Date
    May 2013
    Posts
    5

    Read txt file using javascript and display the content in simple html file

    Hi,

    I have a simple html page, I want to read some other file using java script and display the content. It looks simple, but when I tried facing many issues. Anybody has sample code with simple example, please share with me.

    Thanks in advance!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350

    Question

    Quote Originally Posted by sakthi.99it View Post
    Hi,

    I have a simple html page, I want to read some other file using java script and display the content. It looks simple, but when I tried facing many issues. Anybody has sample code with simple example, please share with me.

    Thanks in advance!
    Please show what you have attempted so far.
    What does your "simple html page" look like?
    What is the contents of the "some other file" look like? Simple text or more HTML script?
    Are your attempts with some 'ajax' solution or something else?

  3. #3
    Join Date
    May 2013
    Posts
    5
    Tried something like this

    <html>
    <head>
    <script>
    function readfile() {
    alert(document.getElementById('iframe').contentDocument.body.firstChild.innerHTML);
    }
    </script>
    </head>
    <body>
    <iframe id='iframe' src = 'test.txt' onload='readfile()'> </iframe>
    <h1>Hello World!</h1>
    </body>

    </html>

    Content of sample.txt file

    This is the sample text file

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Opera, FF and Safari worked ok with that code. i think you are telling us not the whole truth about the real content of your txt-file <wink>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  5. #5
    Join Date
    May 2013
    Posts
    5
    Did you get alert message? I want the file content in a string not to any tag.

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350
    Look into an 'ajax' file reader code solution.

    There are a bunch on the web and you will find many with a simple search of this forum.

    See post #12 of:
    http://www.webdeveloper.com/forum/sh...ht=ajax+loader
    for one possible solution

  7. #7
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Quote Originally Posted by sakthi.99it View Post
    Did you get alert message? I want the file content in a string not to any tag.
    Opera screenshot http://clip2net.com/s/56Uhsy
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles