Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1368 Can I access a cookie that is created in a different page than the current page?

irt.org | Knowledge Base | JavaScript | Cookie | Q1368 [ previous next ]

Q1368 Can I access a cookie that is created in a different page than the current page?

Yes. If its in a different directory then you may need to set the path property of the cookie so that it is high enough in the directory tree not to prevent a document in one part of the directory tree from being excluded. For example, if you set the path to:

/topdir/dir1

then files in /topdir/dir2 will not be able to access the cookie. But if you set the path to:

/topdir

Then files in all sub-directories of topdir will have access. By default the path is set to:

/

Which means all files on the server have access to the cookie.

You set the path of the cookie by passing a path value to a function similar to the one below:

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.