File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes saving data in JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "saving data in JavaScript" Watch "saving data in JavaScript" New topic
Author

saving data in JavaScript

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
I'm trying to make an application using JavaScript, and am trying to think of some clever ways to get around JavaScript's weak point, which is saving data to files.
(I just know someone is going to tell me that JavaScript was made on purpose not to save data files, therefore it is not a weak point. But I want to save information, so for me it's a weak point.)
One way to save data, is to have the program print out text onto the document, and then the user selects the text and copies it into a text file. Then, when the user wants to input text into the program, the user copies text from the text file and puts it into a text area in the document.
Another way to save data is to use cookies. But I read somewhere that cookies are quite limited in the amount of text that can be saved in them.
Anyone have any clever ideas?
One idea that I have involves having the program read the text off another document. Is there some way for a program to read the text printed directly onto a document(not printed in a text area)? Or is there some way for a program to read the entire content of a document, including HTML tags and scripts, and everything?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Originally posted by Kevin Tysen:

(I just know someone is going to tell me that JavaScript was made on purpose not to save data files, therefore it is not a weak point. But I want to save information, so for me it's a weak point.)


Yup, I'm that someone. It's a strength; the last thing I want is anyone writing data to my system.

and then the user selects the text and copies it into a text file.


And just how many users do you think are going to put up with that?

One idea that I have involves having the program read the text off another document.


What other document? Where?

Another way to save data is to use cookies. But I read somewhere that cookies are quite limited in the amount of text that can be saved in them.


This is true.

Anyone have any clever ideas?


Store it on the server where it belongs. But I'm sure that's not what you want to hear. You're trying to use a hammer to flip pancakes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you want to limit yourself to IE, you always have ActiveX.

Eric
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
About reading the text off another document, what I mean is something like this. Suppose there is a web page made by someone else that I don't have access to edit, but I can read it of course. And the page looks like this:
<HTML><HEAD></HEAD><BODY>
Today's weather: rain
</BODY></HTML>

So I want my program to download this page (the content of which changes because the weather changes every day) and read the words "Today's weather: rain", and then parse it up, or whatever, and use the info in my page. That's what I mean.

About saving the data on the server, is there some way to do that only by using JavaScript, and not CGI? And can you read the data again?

The program I'm working on now, actually I wrote it already in Java, and I've been using it. But now I want to have other people use it too, but I don't think they will all want to download the JRE, so I want to use JavaScript, because virtually everyone has it already on their internet browsers.
Well, thank you for the helpful advice.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Originally posted by Kevin Tysen:

So I want my program to download this page (the content of which changes because the weather changes every day) and read the words "Today's weather: rain", and then parse it up, or whatever, and use the info in my page. That's what I mean.


Assuming that the page is available from the same domain, you can use Ajax to read it in. If it's valid XML it will be easy to parse. if not, not so easy.

If the page is not hosted on the same site, you're out of luck again as you'll need a server-side cross-server proxy to obtain the document.

About saving the data on the server, is there some way to do that only by using JavaScript, and not CGI?


No.

but I don't think they will all want to download the JRE


No one needs to download a JRE in order to use a Java-powered site. The Java exists on the server, not the client. (Not talking about Applets here which is another matter orthogonal to this discussion).
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
"No one needs to download a JRE in order to use a Java-powered site. The Java exists on the server, not the client."

Using a Java program on a server would be considered as 'using CGI', wouldn't it? The contract I have with my internet service provider lets me have a home page, but I can't write my own CGI scripts.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

My next step would be to find a better provider. Seriously. You are trying to fly in a straight-jacket.
Arjumand Bonhomme
Greenhorn

Joined: Feb 28, 2007
Posts: 6
Not sure exactly what you are trying to accomplish, but this article might be of some use to you.
Brad Neuberg's blog posting on Dojo.Storage

I haven't tried it yet myself, but it does claim to offer a solution for offline storage of data.
 
Don't get me started about those stupid light bulbs.
 
subject: saving data in JavaScript