/    Sign up×
Community /Pin to ProfileBookmark

cross domain cookie

I have a CD using frames that at some points loads a page from the server. This page needs to be able to read a cookie set by a different frame (the html page will be located on a CD on a local drive).

Below is part of the test I am doing: I have set the domain but the cookie (which works fine without domain set) will not work with it set here.

If the below code is right then I must have the domain name written wrong and will have to go throught the IT dept here (which means it could be days before I get a response), so I am hoping some of the code is wrong…

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + “=” + escape(value) +
((expires) ? “; expires=” + expires.toGMTString() : “”) +
((path) ? “; path=” + path : “”) +
((domain) ? “; domain=” + domain : “”) +
((secure) ? “; secure” : “”);
document.cookie = curCookie;
}

OK then I set the cookie here:

setCookie(“counter”, visits, now, “/”, “mydomain.com”);

with ‘visits’ and ‘now’ being variables.

Gracias

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@pyroFeb 26.2003 — Unless you set the cookie from the website (while online) you won't be able to access it with you online pages. The reason is cookies can only be accessed from the domain that set them, so if you set them from the localdisk, you won't be able to access them with you online page. What you will want to do is use your offline page to read the cookie and put the value into a variable so you can read it with your online page....
Copy linkTweet thisAlerts:
@mikehdauthorFeb 27.2003 — I tried doing that, setting cookie locally, setting variable locally, then reading the variable from my online page, and I get an access denied JS error.

I just figured an online page couldn't get a variable ect... from a local page.

If this is not the case maybe I will have to revist that and double check my code.

thanks
Copy linkTweet thisAlerts:
@pyroFeb 27.2003 — You will have to _pass_ the variable to the new page. (ie. the address bar). Definitely not the most secure thing in the world, as the value of you cookie will have to be concatenated to the address something like this. http://www.your.com?cookievar=yourcookievalue and you can then split it of later...
Copy linkTweet thisAlerts:
@mikehdauthorFeb 27.2003 — Thanks for the info, but I think I will have to do something else. This 'cookie' would contain test scores and some log in info, so I'll probably have to do some sort of install so I can keep track of these items

Gracias
×

Success!

Help @mikehd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...