View Full Version : Opening and editing files in Javascript

12-31-2003, 02:15 PM
I've looked with Google, through Liorean's documentation threads and searched this forum, but I can't find how to open and edit files with Javascript! I thought it might be the classic var file = fopen('filename', 'mode'); but that doesn't seem to work. Any advice?

12-31-2003, 04:02 PM
Never mind, I rephrased my search terms and it came up with a lot of different answers... bleh. This makes my life difficult.

Willy Duitt
12-31-2003, 05:09 PM
If it helps me'

Here is one method Vinny posted once:

<script type="text/javascript">

// author: Vincent Puglia
// site: http://members.aol.com/grassblad

function loadFile(oSrc, oDest)
var fso, oFile, contents
var ForReading = 1
var txtFile = oSrc.value;
fso = new ActiveXObject("Scripting.FileSystemObject")
oFile = fso.OpenTextFile(txtFile, ForReading)
contents = oFile.ReadAll()

oDest.value = contents;

<form name="a">
<input type="file" name="b">
<input type="button" value="Load It" onclick='loadFile(this.form.b, this.form.c)'>
<textarea name="c" cols="80" rows="25"></textarea>