Can I save a text file?

T

Thomas Magma

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
 
E

Evertjan.

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.
 
T

Thomas Magma

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

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
 
E

Evertjan.

Thomas Magma wrote on 31 mrt 2006 in comp.lang.javascript:
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.
 
T

Thomas 'PointedEars' Lahn

Thomas said:
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
 
J

Jim

Thomas said:
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>
 
T

Thomas Magma

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
 
T

tihu

Thomas said:
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
 
T

Thomas Magma

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top