Stephan Schulz wrote:
> [...] Thomas 'PointedEars' Lahn wrote:
>> Local files have no domain which is the reason why cookies do not work
>> reliably via the `file:' URI scheme.
>
> Hummm...is there any way to make it work unreliably?
Perhaps you meant to ask "Is there any way to make it work reliably?" since
it already works unreliably

The answer would be: No, there is not. A
user agent may or may not support cookies for the `file:' URI scheme.
> For the online version, it's important to make it work as widely as
> possible. For the local copy, it's OK if I can make it run in Safari
> or Firefox (or, preferably, both).
Try this:
<body>
<script type="text/javascript">
document.write('document.cookie = ' + document.cookie + "<br>\n");
document.write('document.cookie = ' + navigator.userAgent);
var d = new Date();
document.cookie = "foo=" + d.toGMTString()
+ "; expires="
+ new Date(d.getTime() + 24*3600000).toGMTString()
+ "; path=/home/scripts/test"; // modify to fit your needs
</script>
</body>
Surprising to me, it appears to work reliably in
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.

Gecko/20060110
Debian/1.5.dfsg-4 Firefox/1.5 Mnenhy/0.7.3.0
and
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20051007
Debian/1.7.12-1
It is even possible to specify the `path' component to allow `file://'
cookies to work between files in different directories. It is required
that the `domain' component is omitted, i.e. `domain=' or
`domain=localhost' does not work. Note that those cookies will be set
with domain `scheme:file', so if you look for the appropriate cookie rule
(which may have been set by having the checkbox in the cookie message box
checked), you have to look for this.
Cookies for `file://' resources do not appear to work in
Mozilla/5.0 (compatible; Konqueror/3.5; Linux 2.6.14.4-20051220.153223+0100;
X11; i686; de, en_US) KHTML/3.5.0 (like Gecko) (Debian package 4:3.5.0-3)
which is why I assume they will also not work in Safari (both use KHTML as
layout engine and KJS as script engine): the cookies can be set there (or
so it seems) but they cannot be retrieved later.
>> However, if it is a _program_ that
>> is _run_ from a local _file_, there is no reason why this program could
>> not obtain a file handle for accessing the local file system.
>
> It's JavaScript, embedded in HTML. I consider it a program, but it is
> not a stand-alone binary. It's executed by the interpreter of the
> browser. If there are file-handling functions in JavaScript, they have
> escaped me so far (which would not be a surprise...I' started writing
> this thing 2 weeks ago or so, and it's my first JavaScript project).
If you do not want to use cookies (with the restrictions described above),
you will have to use at least UA-specific host objects. For Gecko-based
browsers these would be XPCOM file objects available in privileged script;
for IE, it would be the FileSystemObject ActiveX/COM object.
<URL:http://xulplanet.com/references/xpcomref/group_Files.html>
<URL:http://msdn.microsoft.com/library/en-us/script56/html/af4423b2-4ee8-41d6-a704-49926cd4d2e8.asp>
As for Safari, I am afraid that the KHTML DOM does not appear to provide for
such an object:
<http://developer.kde.org/documentation/library/3.4-api/khtml/html/index.html>
But it is entirely possible that I overlooked something.
PointedEars