Is it possible to set a page specific cookie?
I know it is possible to set a cookie for a path such as "/" or "/folder/", but is it possible to set a cookie f开发者_StackOverflow中文版or a specific page, such as "/folder/page.html"?
No.
More specifically, browsers don't care about page specifics -- only paths. Browsers submit cookies on page requests based on the path of the url; the specific resource at that location is irrelevant.
On the flip side, why would you want to limit a cookie based on a specific page?
I just insert the page name into the cookie and retrieve based on that name.
var parts = window.location.pathname.split('/');
var pageName = parts[parts.length -1];
var baseNmae = 'somebase';
var cookieName = baseName + '_' + pageName;
then save/read cookie with cookieName
name.
(make sure your path is set for the cookie too)
精彩评论