Read text file from JAVASCRIPT

0

I am trying to create a function that reads all the contents of a text file and then visualizes everything in a new window. For now this is my code:

function leeArchivo(file)
        {
            var archivo = new XMLHttpRequest();
            archivo.open("GET", file, false);
            archivo.onreadystatechange = function ()
            {
                if(archivo.readyState === 4)
                {
                    if(archivo.status === 200 || archivo.status == 0)
                    {
                        var Texto = archivo.responseText;
                        myWindow.document.write (Texto);
                    }
                }
            }
            archivo.send(null);
        }

I call the function later, passing as a parameter the path of my file:

leerArchivo("prueba.txt");

The problem is that this is how the window is displayed:

I would like it to look like a normal text file, without the data above and with the corresponding spacing.

Thank you very much.

    
asked by user5673573 23.09.2018 в 15:44
source

0 answers