Results 1 to 5 of 5

Thread: Javascript write to file

  1. #1
    Join Date
    Dec 2008
    Posts
    27

    Javascript write to file

    I'm trying to make a simple webpage where user enter his name and that name should be save in a text file. I mean whenever users clicks on the submit button everytime the entered the name should be save in one text file. It would be really helpful to me if you'll provide JavaScript code to write in to a file? Many many thanks

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Javascript write to file

    Javascript - Reading a file : Consider the code below and add it in your webpage code:

    Code:
    fh = fopen(getScriptPath(), 0 ); // Open the file for reading
    if (fh!=- 1 ) // If the file has been successfully opened
    {
        length = flength(fh);         // Get the length of the file    
        str = fread(fh, length);     // Read in the entire file
        fclose(fh);                     // Close the file
        
    // Display the contents of the file    
        write(str);    
    }
    Note: If you won't save the file, getScriptPath() will return an empty string.

  3. #3
    Join Date
    Mar 2008
    Posts
    198

    Re: Javascript write to file

    The below code work for me:

    function WriteToFile() {
    try {
    var fso, s;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    s = fso.OpenTextFile("C:\\test.txt" , 8, 1, -2);
    s.writeline("This is a test");
    s.Close();
    }
    catch(err){
    var strErr = 'Error:';
    strErr += '\nNumber:' + err.number;
    strErr += '\nDescription:' + err.description;
    document.write(strErr);
    }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Javascript write to file

    Google is your friend. The main problem you'll face with this is varied security settings mean its not entirely reliable to expect users to allow the javascript that much access to write to the file system. For settings or a small bit of info, consider saving that in a cookie.

  5. #5
    Join Date
    May 2010
    Posts
    1

    Re: Javascript write to file

    Quote Originally Posted by Din_the1 View Post
    I'm trying to make a simple webpage where user enter his name and that name should be save in a text file. I mean whenever users clicks on the submit button everytime the entered the name should be save in one text file. It would be really helpful to me if you'll provide JavaScript code to write in to a file? Many many thanks
    look at video on <http://trix.exofire.net/>
    Last edited by Saket; 29-05-2010 at 01:09 PM. Reason: External link not allowed

Similar Threads

  1. Write to an XML file without overwriting
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 11:11 AM
  2. Replies: 3
    Last Post: 22-09-2009, 09:38 AM
  3. How to write javascript to Display Block
    By Imdra in forum Windows Software
    Replies: 3
    Last Post: 12-08-2009, 01:00 PM
  4. How to write javascript isobject
    By Zombi in forum Software Development
    Replies: 3
    Last Post: 28-07-2009, 11:54 AM
  5. How to write Cookies in Javascript
    By Janet J in forum Windows Software
    Replies: 3
    Last Post: 30-01-2009, 11:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,116,497.94811 seconds with 17 queries