473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can I save a text file?

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
11 18949
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
>
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
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
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
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
>
I must have answered that question about 10 times now here.
PointedEars


Care to make it eleven?
Mar 31 '06 #7
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
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
>
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: BadOmen | last post by:
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible? Then when I read the...
3
by: Newbie | last post by:
I am trying to get the save/open dialog figured out. I am able open the save dialog but when I put in a file name (whatever.txt) and save the file does save with the name but it is blank. Below...
2
by: gnv | last post by:
Hi all, I am writing a cross-browser(i.e. 6 and netscape 7.1) javascript program to save an XML file to local file system. I have an xml string like below: var xmlStr = "<?xml version="1.0"...
0
by: a | last post by:
Save text file as html kloepper 17:42 23 Jul '04 I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
10
by: GJP | last post by:
Hello. Ive been asked to make my own notepade for college assignment. All ig going well, but i cant get the save to work. I can get Save a (shows dialog box), i can get it to just save too,...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
2
by: nuhura01 | last post by:
Hi.. I'm trying to save query path which is in text box to text file. Below is the coding that i'm using currently: Private Sub SaveQueryPath() 'save to text file Response.Clear()...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.