Print the contents of a text file using javascript/jquery

I have a text file in my system. I want print the contents of that text file using javascript/jquery. How can I do that. I have referred the Link. But it is simply printing from div. I need to use window.print() method. But how can I print the text file using javascript? Please guide me.

Answers 1

  • i think you need back-end (php,rails,nodejs) support for reading file from computer and then display it on any HTML Block then Print this is most preferable way to print a file

    you can use below syntax if you have back-end setup and file must be on your server

    $(document).ready(function () {

     $("button").click(function () {
            $.ajax({
                url : "Content.txt",
                dataType: "text",
                success : function (result) {
                    $("#container").html(result);
                }
            });
        });
    });
    

Related Articles