2

I need a database storage system for Javascript where the state can be maintained on the local disk.

Here comes the spanners in the works :-

  • It only needs to support Internet Explorer but the minimum version must be IE6
  • Files need to be written so they can be read in again later (upon closing and re-opening of browser)
  • There can be no web server (unless it's extremely easy to distribute and does not require a install) since the HTML pages will be distributed on USB.

Does anyone know of any solutions that might help here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Julian Young
  • 872
  • 2
  • 9
  • 21

5 Answers5

2

I don't know if it's supported in IE6, but JScript appears to have some level of support for this through FileSystemObject.

var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("c:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

According to Write binary data with FileSystemObject write(), ADODB.Stream appears to be an alternative.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • FileSystemObject will work from IE6 but it requires elevated permissions not typically granted to HTML content on a USB drive. I have tried this approach and it turns out to be a support problem because none of my users could get it to "just work" ... they all had to monkey with their system security settings. – Mark Ewer Apr 12 '11 at 16:17
  • @Mark Ever: To avoid these problems, use .HTA (files/applications) instead of .HTML. – Ekkehard.Horner Apr 12 '11 at 16:26
  • I think what Mark has said about permission issues rules this out, I need something userfriendly. +1 for the coding example and research though, thanks :) – Julian Young Apr 12 '11 at 19:26
2

Have fun playing with userData. Apparently it does what you want in IE6/7

Then localStorage for IE8/9

Or you can use the heavier store.js which does the feature detection for you and apparently works in IE6+.

It should work in IE9 but no garantuees. I would recommend store.js as it's easier for maintenance and just works out of the box. You can also support other browsers that way.

Raynos
  • 166,823
  • 56
  • 351
  • 396
  • Note my stipulation of "Files need to be written so they can be read in again later (upon closing and re-opening of browser)". Is userData / localStorage persistant past opening and closing the beowser? I was under the impression it wasn't but maybe I am wrong. – Julian Young Apr 12 '11 at 19:03
  • @JulianYoung local storage is persistant. SessionStorage is not. userData is good luck ;) – Raynos Apr 12 '11 at 19:34
  • Just an update to say store.js worked a treat across all IE versions we tested. We have been compressing large JSON data objects and storing them as strings via store.js - It's enough for a small database. – Julian Young Apr 22 '11 at 14:06
  • @JulianYoung good to know. I'll use store.js for when I need to support IE6 :) – Raynos Apr 22 '11 at 14:08
2

For strictly local IE work use HTA Applications. Then you can access local resources (text files, ADO databases) without security problems.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
1

try to read this post: Read/write to file using jQuery

Hope this helps.

Community
  • 1
  • 1
alexl
  • 6,841
  • 3
  • 24
  • 29
  • Thanks for that link, whilst it's not very helpful for my rather contrained requirements it did have an interesting link to http://jquery.tiddlywiki.org/twFile.html which I will be looking at. – Julian Young Apr 12 '11 at 19:18
1

I would suggest that you not try to read/write using JavaScript but instead head down the road of embedding a small web server on the USB drive. I did this for an app once and it worked out well. I used the Cassini web server.

I created two projects in visual studio. First, I created an ASP.Net web site to read/write from an SQLite database. This site displayed all my content and was built just like any other ASP.Net site. Second, I created a Windows Forms application that hosted the Cassini web server and presented the user with a form that contained a single web browser control. This made the user experience very simple ... they just clicked MYAPP.EXE from the root of the USB drive and the form opens, starts the web server, and navigates the browser control to the start page of the web site.

Mark Ewer
  • 1,835
  • 13
  • 25