I need to write to a file.

A

alex@techdoc

Hello All,

I'm designing a an interface for my company and I need to be able to
interface with a text file. I chose Javascript for this because up
until this requirement surfaced, it's been the perfect tool.

How do I write to a text file using Javascript when you don't have
access to a server?

For reasons that I don't want to get into (political) I don't have
access to a web server so I can't do HTTP requests. It's all client-
side--ALL of it. Except for this issue, they love it.

Alex
 
D

David Mark

Hello All,

I'm designing a an interface for my company and I need to be able to
interface with a text file. I chose Javascript for this because up
until this requirement surfaced, it's been the perfect tool.

How do I write to a text file using Javascript when you don't have
access to a server?

For reasons that I don't want to get into (political) I don't have
access to a web server so I can't do HTTP requests. It's all client-
side--ALL of it. Except for this issue, they love it.

Alex

In IE you use an ActiveX object. Google "javascript filesystemobject."
 
T

Thomas 'PointedEars' Lahn

alex@techdoc said:
I'm designing a an interface for my company and I need to be able to
interface with a text file. I chose Javascript for this because up
until this requirement surfaced, it's been the perfect tool.

How do I write to a text file using Javascript when you don't have
access to a server?

That depends on your targeted execution environments. ECMAScript
implementations are but programming languages, the keys to the toolbox.
You will need to open the proper toolbox (API) to bring it to use.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
glegroups.com>, Wed, 26 Sep 2007 14:55:22, "alex@techdoc"
How do I write to a text file using Javascript when you don't have
access to a server?

As a last resort, write to a textarea and describe the use of Select
All, Copy, Paste into Notepad, and Save. But verify that newlines, and
any characters outside the common range, are correctly handled.

That assumes Windows. Something similar may be available in Mac, Sun,
etc.

When describing non-public systems, always indicate restrictions. They
can be advantageous or disadvantageous, but are generally significant.
 
G

GArlington

Hello All,

I'm designing a an interface for my company and I need to be able to
interface with a text file. I chose Javascript for this because up
until this requirement surfaced, it's been the perfect tool.

How do I write to a text file using Javascript when you don't have
access to a server?

For reasons that I don't want to get into (political) I don't have
access to a web server so I can't do HTTP requests. It's all client-
side--ALL of it. Except for this issue, they love it.

Alex

Are you trying to read a file FROM clients computer?
JS (pure) will not allow that for security reasons, otherwise ANY web
site could read ANY private information on your HDD when you come to
visit their site - think about it.
Or are you trying to read a file from the web server?
AJAX is one (of the) tool(s) that will allow you to do that, alt you
can always use DOM method createElement("SCRIPT"), if your file is
scriptable, or use an iFrame to read it, or ...
There are to many methods to list.
 
A

alex@techdoc

Security is not an issue for the interface that I'm writing. It's all
client-side as my Javascript program displays
"w.document.write(yaddayadda)" based on a series of user options. A
server is never involved. The required information only needs to be
displayed but not stored anywhere. But lately my client has expressed
an interest in archiving what users do. So I either have to convert
everything to something like Perl (don't want to do that) or figure
out how to get Javascript to write out a file without HTTP
involvement--essentially behave like Perl or a some such language. I
understand that Javascript was not designed for that but programmers
often come up with novel ways of making things work despite the
planned capabilities of a computer language.

So I'm looking for one of those novel approaches. Other than AJAX or
an FSO, I'm out of ideas--thought maybe someone here might have
another angle into this.
 
D

David Mark

Security is not an issue for the interface that I'm writing. It's all
client-side as my Javascript program displays
"w.document.write(yaddayadda)" based on a series of user options. A
server is never involved. The required information only needs to be
displayed but not stored anywhere. But lately my client has expressed
an interest in archiving what users do. So I either have to convert
everything to something like Perl (don't want to do that) or figure
out how to get Javascript to write out a file without HTTP
involvement--essentially behave like Perl or a some such language. I
understand that Javascript was not designed for that but programmers
often come up with novel ways of making things work despite the
planned capabilities of a computer language.

Since JS has ccncept of files, you have to use a host object.
So I'm looking for one of those novel approaches. Other than AJAX or
an FSO, I'm out of ideas--thought maybe someone here might have

I don't see how AJAX will help you without a server, but what is wrong
with using the FileSystemObject? Since this is an Intranet app, just
name IE as the required browser and have your network admin deploy the
appropriate security configuration. If you don't want to use IE, look
for a similar plugin for Mozilla.
 
L

Lee

alex@techdoc said:
Security is not an issue for the interface that I'm writing. It's all
client-side as my Javascript program displays
"w.document.write(yaddayadda)" based on a series of user options. A
server is never involved. The required information only needs to be
displayed but not stored anywhere. But lately my client has expressed
an interest in archiving what users do. So I either have to convert
everything to something like Perl (don't want to do that) or figure
out how to get Javascript to write out a file without HTTP
involvement--essentially behave like Perl or a some such language. I
understand that Javascript was not designed for that but programmers
often come up with novel ways of making things work despite the
planned capabilities of a computer language.

It's not a matter of trying to extend the capabilities of the
language, you're asking for help hacking around the designed
security restrictions.

If you need to convert a web page to a client-based application,
you might look into Microsoft's "Hypertext Application" hybrid.
They allow you to use fso without the security restrictions.


--
 
T

Thomas 'PointedEars' Lahn

alex@techdoc said:
[...] But lately my client has expressed an interest in archiving what
users do.

Won't cookies suffice?
So I either have to convert everything to something like Perl (don't want
to do that) or figure out how to get Javascript to write out a file
without HTTP involvement--essentially behave like Perl or a some such
language. I understand that Javascript was not designed for that but
programmers often come up with novel ways of making things work despite
the planned capabilities of a computer language.

So I'm looking for one of those novel approaches. Other than AJAX

"AJAX" fortunately cannot write to filesystems.
or an FSO,

That would the the MSHTML way.
I'm out of ideas--thought maybe someone here might have another
angle into this.

This would be the Gecko way:

http://developer.mozilla.org/en/docs/XPCOM_API_Reference#Files_and_Directories
[top post]

Please don't do that again.

http://jibbering.com/faq/


PointedEars
 
H

Henri

Security is not an issue for the interface that I'm writing. It's all
client-side as my Javascript program displays
"w.document.write(yaddayadda)" based on a series of user options. A
server is never involved. The required information only needs to be
displayed but not stored anywhere. But lately my client has expressed an
interest in archiving what users do. So I either have to convert
everything to something like Perl (don't want to do that) or figure out
how to get Javascript to write out a file without HTTP
involvement--essentially behave like Perl or a some such language. I
understand that Javascript was not designed for that but programmers
often come up with novel ways of making things work despite the planned
capabilities of a computer language.

So I'm looking for one of those novel approaches. Other than AJAX or an
FSO, I'm out of ideas--thought maybe someone here might have another
angle into this.

you can use an ajax call to a php script that'll handle the writing.
 
T

Thomas 'PointedEars' Lahn

Henri said:
[...] So I either have to convert everything to something like Perl
(don't want to do that) or figure out how to get Javascript to write
out a file without HTTP involvement [...]
^^^^^^^^^^^^^^^^^^^^^^^^
you can use an ajax call to a php script that'll handle the writing.

See the markings above.

And please trim your quotes. http://jibbering.com/faq/


PointedEars
 
P

psema4

How do I write to a text file using Javascript when you don't have
access to a server?

For reasons that I don't want to get into (political) I don't have
access to a web server so I can't do HTTP requests. It's all client-
side--ALL of it. Except for this issue, they love it.

Hi Alex,

I'd recommend looking at the TiddlyWiki source code. TW is a client-
side "non-linear notebook" (although there are server-based variants)
that works in a number of different browsers. Persistence is handled
by reading and writing to HTML files on the client machine.

Being under a BSD style license, I'm using the relevant portions of
the TiddlyWiki source to provide persistence in my project, Atomic
OS. Look for function declarations that begin with the word "save."

http://www.tiddlywiki.com/

HTH,
- Scott.
 
H

Henri

without HTTP involvement [...]
^^^^^^^^^^^^^^^^^^^^^^^^
you can use an ajax call to a php script that'll handle the writing.
well... let's see... hopefully, one day, the site will be operating in a
server environment, right? So, unless it's meant to stay offline (and I
don't see what would be the point), our friend here might as well take
advantage of this environment and use http, no?
That's all I'm saying
 

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

No members online now.

Forum statistics

Threads
474,155
Messages
2,570,871
Members
47,401
Latest member
CliffGrime

Latest Threads

Top