非服务器页面中的Cookie? [英] Cookies in non-server pages?

查看:87
本文介绍了非服务器页面中的Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是一个相当陌生的JavaScript,并且找不到解决

问题的方法:


我用DHTML / JavaScript编写了一个应用程序,因为我希望能够在网上提供访问权限,但主要是因为它

是我用便携式

方式组合GUI和布局的最简单方法。


万一你想知道,它是一个用于纸笔的角色生成器

角色扮演游戏( http://www.eprover.org/ROLESIM/chargen2.html -

德语,但代码和评论(大部分)是英语)。


它仍然是初步的,但工作正常。但是,我第一次使用它时,他们立即想要保护他们的角色,以便稍后更新

。我知道JavaScript无法直接访问

本地文件系统(并且有充分的理由),但是我们想出了一个将字符配置文件存储在一个中的想法

cookie。


我的第一个测试似乎有效,但只有当页面实际上通过网络服务器提供时才能获得
。更常见的用例是程序是从本地文件运行的
。在这种情况下,似乎cookie根本没有设置为



有没有解决这个问题的方法(缺少合作的运行)每个用户计算机上的
webserver)?也许这只是一个问题,

设置正确的域名?


谢谢!


再见,


斯蒂芬


-

--------------- - - - - - - 可以办到! ---------------------------------

请发邮件给我 sc **** @ eprover.org (Stephan Schulz)

------------ -------------------------------------------------- --------------

Hi all,

I''m fairly new to JavaScript, and couldn''t find a way to solve the
following problem:

I''ve written an application in DHTML/JavaScript, for one because I
want to be able to offer access on the web, but primarily because it
was the easiest way for me to combine GUI and layout in a portable
manner.

In case you wonder, it is a character generator for pen-and-paper
roleplaying game (http://www.eprover.org/ROLESIM/chargen2.html -
German language, but code and comments are (mostly) English).

It is still preliminary, but works fine. However, the first time my
users used it, they immediately wanted to safe their characters for
later updates. I know that JavaScript has no direct access to the
local file system (and for good reasons), but we came up with the idea
of storing a character profile in a cookie.

My first test seems to work, but only when the page is actually served
via a web server. The more frequent use case is that the program is
run from a local file. In tat case, it seems that the cookie is not
set at all.

Is there any way around this problem (short of running a cooperating
webserver on each users computer)? Maybe it''s just an issue with
setting the proper domain?

Thanks!

Bye,

Stephan

--
-------------------------- It can be done! ---------------------------------
Please email me as sc****@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------

推荐答案

Stephan Schulz写道:
Stephan Schulz wrote:
我的第一个测试似乎有效,但只有在页面实际通过Web服务器提供时才会生效。更常见的用例是程序是从本地文件运行的。在这种情况下,似乎根本没有设置cookie。

有没有解决这个问题的方法(没有在每个用户计算机上运行合作的
网络服务器) ?也许这仅仅是设置正确域名的问题?
My first test seems to work, but only when the page is actually served
via a web server. The more frequent use case is that the program is
run from a local file. In tat case, it seems that the cookie is not
set at all.

Is there any way around this problem (short of running a cooperating
webserver on each users computer)? Maybe it''s just an issue with
setting the proper domain?




本地文件没有域名,这就是为什么cookie不起作用的原因

可靠地通过`file:''URI方案。但是,如果它是_program_,

是来自本地_file_的_run_,则没有理由为什么这个程序可能无法获得用于访问本地文件系统的文件句柄。

PointedEars



Local files have no domain which is the reason why cookies do not work
reliably via the `file:'' URI scheme. 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 filesystem.
PointedEars


文章< 43 **************** @ PointedEars.de> ,托马斯''PointedEars''Lahn写道:
In article <43****************@PointedEars.de>, Thomas ''PointedEars'' Lahn wrote:
Stephan Schulz写道:
Stephan Schulz wrote:
我的第一个测试似乎有效,但只有当页面实际服务时
通过Web服务器。更常见的用例是程序是从本地文件运行的。在这种情况下,似乎根本没有设置cookie。

有没有办法解决这个问题(没有在每个用户计算机上运行合作的
网络服务器) ?也许这只是设置正确域名的问题?
本地文件没有域名,这就是为什么cookie无法通过`file:''URI方案可靠地工作的原因。
My first test seems to work, but only when the page is actually served
via a web server. The more frequent use case is that the program is
run from a local file. In that case, it seems that the cookie is not
set at all.

Is there any way around this problem (short of running a cooperating
webserver on each users computer)? Maybe it''s just an issue with
setting the proper domain?
Local files have no domain which is the reason why cookies do not work
reliably via the `file:'' URI scheme.




Hummm ...有什么方法可以让它不可靠地工作?对于在线

版本,让它尽可能广泛地工作是很重要的。对于

本地副本,如果我可以在Safari或Firefox中运行它(或者,最好是两个b $ b),这是可以的。

但是,如果它是_program_,
是来自本地_file_的_run_,则没有理由为什么该程序无法获取用于访问本地文件系统的文件句柄。



Hummm...is there any way to make it work unreliably? 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).
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.




它是嵌入在HTML中的JavaScript。我认为它是一个程序,但它不是一个独立的二进制文件。

。它由

浏览器的翻译执行。如果在JavaScript中有文件处理函数,他们到目前为止已经逃过我了(这不会是一个惊喜......我已经开始写了

这个东西2几周前左右,这是我的第一个JavaScript项目。


非常感谢!


再见,
< br $>
斯蒂芬


-

-------------------- - - - 可以办到! ---------------------------------

请发邮件给我 sc **** @ eprover.org (Stephan Schulz)

------------ -------------------------------------------------- --------------



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).

Thanks anyways!

Bye,

Stephan

--
-------------------------- It can be done! ---------------------------------
Please email me as sc****@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------


Stephan Schulz写道:
Stephan Schulz wrote:
[...] Thomas''PointedEars''Lahn写道:
[...] Thomas ''PointedEars'' Lahn wrote:
本地文件没有域名,这就是为什么cookie不能通过`file:''URI方案可靠地工作的原因。嗯...有什么方法可以让它不可靠地工作吗?
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?




也许您打算问有什么方法可以让它可靠地工作吗?因为

它已经不可靠了:)答案是:不,没有。一个

用户代理可能支持也可能不支持`file:''URI方案的cookie。

对于在线版本,重要的是让它工作为广泛如可能。对于本地副本,如果我可以在Safari
或Firefox(或者最好是两者)中运行它是可以的。



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).




试试这个:


< 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()

+" ;;路径= /家庭/脚本/测试英寸; //修改以满足您的需求

< / script>

< / body>


令我惊讶的是,它


Mozilla / 5.0(X11; U; Linux i686; en-US; rv:1.8)Gecko / 20060110

Debian / 1.5 .dfsg-4 Firefox / 1.5 Mnenhy / 0.7.3.0




Mozilla / 5.0(X11; U; Linux i686; en- US; rv:1.7.12)Gecko / 20051007

Debian / 1.7.12-1


甚至可以指定`path''组件允许`file://''

cookie在不同目录中的文件之间工作。需要

省略`domain''组件,即`domain =''或

`domain = localhost''不起作用。请注意,这些cookie将设置为

,域名为scheme:file,因此如果您查找相应的cookie规则

(可能是通过设置Cookie消息框中的复选框

已选中),您必须查找此内容。


file://资源的Cookie似乎不显示工作


Mozilla / 5.0(兼容; Konqueror / 3.5; Linux 2.6.14.4-20051220.153223 + 0100;

X11; i686; de,en_US)KHTML /3.5.0(像Gecko一样)(Debian软件包4:3.5.0-3)


这就是为什么我认为它们也不适用于Safari(两者都使用KHTML作为

布局引擎和KJS作为脚本引擎):可以在那里设置cookie(或者看起来好像是b $ b)但是以后无法检索它们。



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.8) 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.

但是,如果它是_program_,
是来自本地_file_的_run_,那么这个程序没有理由不能获取文件句柄来访问本地文件system。
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.



它是嵌入在HTML中的JavaScript。我认为它是一个程序,但它不是一个独立的二进制文件。它由
浏览器的翻译执行。如果在JavaScript中有文件处理功能,他们到目前为止已经逃过了我(这不会是一个惊喜......我已经开始写这个东西2周前左右,而且它'这是我的第一个JavaScript项目。)



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).




如果你不想使用cookies(有上述限制),

你会必须至少使用特定于UA的主机对象。对于基于Gecko的
浏览器,这些将是特权脚本中可用的XPCOM文件对象;对于IE,它是
,它将是FileSystemObject ActiveX / COM对象。


< 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>


至于Safari,我担心KHTML DOM似乎没有提供

这样一个对象:


< http://developer.kde.org/documentation/library/3.4-api/khtml/html/index。 html>


但我完全有可能忽略了一些东西。

PointedEars



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


这篇关于非服务器页面中的Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆