By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 1,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

Can I save a text file?

P: n/a
I have a simple JavaScript application that will generate some text type
data for the end user. Is it possible to have a button that will allow them
to save this information to a text file?

Thomas
Mar 31 '06 #1
Share this Question
Share on Google+
11 Replies

P: n/a
Thomas Magma wrote on 31 mrt 2006 in comp.lang.javascript:
I have a simple JavaScript application that will generate some text
type data for the end user. Is it possible to have a button that will
allow them to save this information to a text file?


Not clientside with normal security settings.
The client's hard-disk is out of reach, and should be so.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 31 '06 #2

P: n/a
>
Not clientside with normal security settings.
The client's hard-disk is out of reach, and should be so.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


I agree that giving webpages the ability to read or write to the harddrive
would be a security nightmare. I'm just wondering on the best approach to
allowing a end user the ability to save information processed by JavaScript.
Aside from taking a picture of his monitor. I guess one option is to write
the information to a large text box where an end user can simply copy and
paste it to his own text file. Anyone know of any other methods of saving
text data?

Thomas

Mar 31 '06 #3

P: n/a
Thomas Magma wrote on 31 mrt 2006 in comp.lang.javascript:

Not clientside with normal security settings.
The client's hard-disk is out of reach, and should be so.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


I agree that giving webpages the ability to read or write to the
harddrive would be a security nightmare. I'm just wondering on the
best approach to allowing a end user the ability to save information
processed by JavaScript. Aside from taking a picture of his monitor. I
guess one option is to write the information to a large text box where
an end user can simply copy and paste it to his own text file. Anyone
know of any other methods of saving text data?


Javascript can fill the clipboard,
so the user only has to paste it in an editor or MS-Word, and save that.

<textarea id='keep'>Text to be copied</textarea>

function copyer(){
var keep = document.getElementById('keep')
var myObj = keep.createTextRange();
myObj.execCommand("Copy");
}

Not tested. IE only I think.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 31 '06 #4

P: n/a
Thomas Magma wrote:
I have a simple JavaScript application that will generate some text type
data for the end user. Is it possible to have a button that will allow
them to save this information to a text file?


I must have answered that question about 10 times now here.
PointedEars
Mar 31 '06 #5

P: n/a
Jim

Thomas Magma wrote:
I have a simple JavaScript application that will generate some text type
data for the end user. Is it possible to have a button that will allow them
to save this information to a text file?


<!-- VBSCRIPT CODING: WORKS ONLY ON MSIE (??)-->
<!-- IT ALSO TRIGGERS AN ALERT TO AUTHORIZE ACTIVE X TO RUN -->
<script type='text/vbscript'>
'html code: <button onClick="cFi( )">Save to C Drive </button>
'set variables:
Dim objFSO, objTextFile
Dim thecode
'start function triggered onClick of button:
Function cFi( )
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

'text file is local drive and file to create that holds the data:
Set objTextFile = objFSO.CreateTextFile("c:\html-code.txt", True)

'thecode variable contains the data n your form you want to save to the
file:
thecode = newWin.document.myform.ta.value
objTextFile.WriteLine(thecode)
objTextFile.Close
End Function
</script>

Mar 31 '06 #6

P: n/a
>
I must have answered that question about 10 times now here.
PointedEars


Care to make it eleven?
Mar 31 '06 #7

P: n/a
Thomas Magma wrote:
I must have answered that question about 10 times now here.


Care to make it eleven?


No. (E.g.) Google is your friend. [psf 6.1]
PointedEars
Mar 31 '06 #8

P: n/a
In article <O%dXf.207609$H%4.1942@pd7tw2no>, "Thomas Magma" <so*******@overtherainbow.com> wrote:

Not clientside with normal security settings.
The client's hard-disk is out of reach, and should be so.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


I agree that giving webpages the ability to read or write to the harddrive
would be a security nightmare. I'm just wondering on the best approach to
allowing a end user the ability to save information processed by JavaScript.
Aside from taking a picture of his monitor. I guess one option is to write
the information to a large text box where an end user can simply copy and
paste it to his own text file. Anyone know of any other methods of saving
text data?

Thomas


Without any fancy solutions, I just have javascript post it to a form field
and email it to them from the form. That way they get a hard copy and can do
what they want with it.

Larry L
Mar 31 '06 #9

P: n/a
>
Without any fancy solutions, I just have javascript post it to a form
field
and email it to them from the form. That way they get a hard copy and can
do
what they want with it.

Larry L


That's a neet idea. I will consider this.

Thanks
Thomas
Mar 31 '06 #10

P: n/a

Thomas Magma wrote:

Without any fancy solutions, I just have javascript post it to a form
field
and email it to them from the form. That way they get a hard copy and can
do
what they want with it.

Larry L


That's a neet idea. I will consider this.

Thanks
Thomas


I know another method which does what you want. Use javascript to post
a form to a script on your server (php/perl.. whatever) and the php
file echoes the text data back to the browser.

Most importantly you must set the "Content-Disposition" http header to
force the Save As dialog box to appear instead of the text being
displayed in the browser.

In php you should set these header's

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="somefile.txt"');
//somefile.txt will the default filename in Save As dialog box - can be
changed by user when it appears

Sometimes this will be more appropriate than the email method,
sometimes the email method will be more useful, depends on what your
doing

hu

Apr 1 '06 #11

P: n/a

I know another method which does what you want. Use javascript to post
a form to a script on your server (php/perl.. whatever) and the php
file echoes the text data back to the browser.

Most importantly you must set the "Content-Disposition" http header to
force the Save As dialog box to appear instead of the text being
displayed in the browser.

In php you should set these header's

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="somefile.txt"');
//somefile.txt will the default filename in Save As dialog box - can be
changed by user when it appears

Sometimes this will be more appropriate than the email method,
sometimes the email method will be more useful, depends on what your
doing

hu


Excellent idea. Thanks.

Thomas
Apr 3 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.