javascript write TXT or Word document

Posted on 2007-07-23
Last Modified: 2012-06-27
I want to write a txt file, word or Xls document from javascript

can you help me?
I tried this

function WriteToFile(sText)
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FileObject = fso.OpenTextFile("C:\\LogFile.cvs", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII

<A HREF="javascript:WriteToFile('sdsdsd.ewewewewe,ererere')">Crear documento</A>
It sends an error "ActiveXObject is not defined"
Question by:Iamme
    LVL 17

    Accepted Solution

    Mozilla or Netscape or FireFox browsers do not allow access to the local file system for security reasons.
    LVL 54

    Assisted Solution

    Those browsers don't even support ActiveX.  Is this in IE or another browser?  The code above will only work in IE but it won't work on an Internet page with default security settings.  Is this an intranet page or one on a website and Internet (look at the bottom, right part of IE to see how it treats the page).

    Let me know more about the page and I can see about suggesting a security setting change but if this is for a public webpage you will not get it to work.  Users and the browser won't want to allow that type of action.

    Let me know if you have a question or need more info.

    LVL 75

    Assisted Solution

    by:Michel Plungjan
    IE will, especially if you give it an extension of .HTA

    Also use this:
    <A HREF="#" onClick="WriteToFile('sdsdsd.ewewewewe,ererere');
    return false">Crear documento</A>
    LVL 54

    Expert Comment

    By the way, this is usually done with server side script and using the server objects.  You will not have the security (user's computer and browser) restrictions doing it on the server.  The server can even send the txt or other file to the browser after it is created.  You could even use server side Javascript if you want.  The key is the browser won't allow webpages to make files, open them, etc on the client's computer.

    If you can use a server language and need help with doing this on the server then let us know.

    LVL 15

    Expert Comment

    1) ActiveX is supported only by MSIE
    2) Even within IE, "Scripting.FileSystemObject"  has strong waves of restrictions for security reasons.
    LVL 54

    Expert Comment

    @Deepaknet - Nice summary but seems to repeat me (http:#19549716).


    Author Comment

    I want to delete this question.....
    LVL 54

    Expert Comment


    Why?  What is the status of this and how did any of the comments above help?

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now