Write ASP-style cookie (with keys) using Javascrip

2019-05-13 22:50发布

In Classic ASP, a single cookie can be a collection of name/value pairs. For instance, a cookie collection named "user" could be created to have keys which contains information about a user:

("user")("firstname")="John"
("user")("lastname")="Smith"
("user")("country")="Norway"
("user")("age")="25"

Is it possible to write that kind of cookie using Javascript, so that ASP would recognize it and parse it accordingly?

1条回答
三岁会撩人
2楼-- · 2019-05-13 23:52

Should be doable.

Your asp example would make a cookie that would look similar to this:

Name:   user
Value:  firstname=John&lastname=Smith&country=Norway&age=25

so when you set your javascript cookies it should be a similar format, try something like:

document.cookie = "user=firstname=John&lastname=Smith&country=Norway&age=25;";
查看更多
登录 后发表回答