1

I want to put a text file into a table cell like below:

                   <td>

                            <script>
                            var t = new Date();
                            var m = t.getMonth()+1;
                            var d = t.getDate();

                            mm = m.toString();
                            dd = d.toString();

                            var f = mm + dd + ".txt";

                            window.location.href = f; 

                            </script>

                    </td>

Only that text file is displayed however. The rest of the webpage isn't shown. i'm guessing it's the "window.location.href = f;" line. What shoud I do instead?

  • If you want to read the file and put content into page, check this - http://stackoverflow.com/questions/14446447/javascript-read-local-text-file – realnero Dec 11 '13 at 14:18

2 Answers2

1

You have a number of options.

  1. Put the content there using a server side technology
  2. Use an iframe
  3. Use the XMLHttpRequest object to fetch the data and then DOM to generate a text node and append it to the table cell
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

The easiest way would be to use IFRAME:

<td>

   <iframe id="ifr" ></iframe>

   <script>
    var t = new Date();
    var m = t.getMonth()+1;
    var d = t.getDate();

    mm = m.toString();
    dd = d.toString();

    var f = mm + dd + ".txt";

    document.getElementById('ifr').src = f; 

    </script>

</td>

You can style the iframe to give width and height as needed.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136