# Write a File with JS

**URL:** <https://www.ruby-forum.com/t/write-a-file-with-js/170378>\
**Category:** Rails\
**Created:** [June 16, 2009, 7:32pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378 "2009-06-16T19:32:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 16, 2009, 7:32pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/1 "2009-06-16T19:32:20Z")

</div>

I want to write into a plain text file using JavaScript (client side),  
how i can do that? Any idea could be good, but a sample could be  
better. grettings 😃

---

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 16, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/2 "2009-06-16T19:41:49Z")

</div>

On Tue, 2009-06-16 at 10:28 -0700, GGC wrote:

> I want to write into a plain text file using JavaScript (client side),

Javascripts do not get access to the local file system. Security. Send  
the data to the server and write the file there. Google ‘javascript  
http post’ for explanation / code.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 16, 2009, 7:48pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/3 "2009-06-16T19:48:53Z")

</div>

You could do this using an ActiveX object, I think.

So something like:

var path = “C:\dir\file.txt”  
var filesystemobject = new ActiveXObject("Scripting.FileSystemObject  
var file = filesystemobject.CreateTextFile(path, true)

// your file manipulations

file.Close()

You might want to look into ActiveXObjects though. I think most  
systems won’t allow you to write to a local path as Bill suggests.

---

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 16, 2009, 10:25pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/4 "2009-06-16T22:25:21Z")

</div>

bill walton wrote:

> On Tue, 2009-06-16 at 10:48 -0700, jhaagmans wrote:
> 
> > You could do this using an ActiveX object, I think.
> 
> This is a Ruby on Rails forum. Is there a way to use ActiveX objects in  
> RoR?

There would almost have to be – my understanding is that they can be  
embedded in Web pages rather like Flash…speaking of which, I have the  
impression that Flash gets more access to the filesystem than JS, so  
that might be worth investigating.

But ActiveX is probably a bad idea in any case. It limits your audience  
to IE on Windows, and I understand there are serious security issues  
with it (as if Windows didn’t already have enough security holes).

> Thanks,  
> Bill

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 16, 2009, 8:05pm UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/5 "2009-06-16T20:05:35Z")

</div>

On Tue, 2009-06-16 at 10:48 -0700, jhaagmans wrote:

> You could do this using an ActiveX object, I think.

This is a Ruby on Rails forum. Is there a way to use ActiveX objects in  
RoR?

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![GGC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@GGC](https://www.ruby-forum.com/u/GGC)\
**Post date:** [June 17, 2009, 4:46am UTC](https://www.ruby-forum.com/t/write-a-file-with-js/170378/6 "2009-06-17T04:46:21Z")

</div>

jhaagmans wrote:

> You could do this using an ActiveX object, I think.

Which is exactly why ActiveX has been one of the most popular attack  
vectors for hacking in the history of computing.
